传递值和传递引用
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
public?class?Transfer?{ //定義2個(gè)變量String?str?=?new?String("good");?//String,是對(duì)象類型————這種情況叫做傳遞引用,原來變量的值不改變,被調(diào)用函數(shù)內(nèi)部的局部變量的值發(fā)生改變char[]?ch?=?{?'a',?'b',?'c'?};???//char,是8種基本數(shù)據(jù)類型中的一種————這種情況叫傳遞值,就是說2個(gè)值都發(fā)生改變public?static?void?main(String?args[])?{Transfer?ex?=?new?Transfer();ex.change(ex.str,?ex.ch);System.out.print(ex.str?+?"?and?");System.out.print(ex.ch);}public?void?change(String?str,?char?ch[])?{str?=?"test?ok";?//原來變量的值,不改變ch[0]?=?'g';?????//原來變量的值,也跟著一起改變} }參考:http://www.cnblogs.com/lanxuezaipiao/p/3371224.html
24.?指出下列程序運(yùn)行的結(jié)果?()
public?class?Example?{String?str?=?new?String("good");char[]?ch?=?{?'a',?'b',?'c'?};public?static?void?main(String?args[])?{Example?ex?=?new?Example();ex.change(ex.str,?ex.ch);System.out.print(ex.str?+?"?and?");System.out.print(ex.ch);}public?void?change(String?str,?char?ch[])?{str?=?"test?ok";ch[0]?=?'g';} }A、?good and abc
B、?good and gbc
C、?test ok and abc
D、?test ok and gbc?
答案:B
轉(zhuǎn)載于:https://my.oschina.net/u/1791074/blog/312542
總結(jié)
- 上一篇: JavaScript-变量与作用域链
- 下一篇: 安装部署VMware vSphere 5