传递值和传递引用
2019獨角獸企業重金招聘Python工程師標準>>>
public?class?Transfer?{ //定義2個變量String?str?=?new?String("good");?//String,是對象類型————這種情況叫做傳遞引用,原來變量的值不改變,被調用函數內部的局部變量的值發生改變char[]?ch?=?{?'a',?'b',?'c'?};???//char,是8種基本數據類型中的一種————這種情況叫傳遞值,就是說2個值都發生改變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.?指出下列程序運行的結果?()
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
轉載于:https://my.oschina.net/u/1791074/blog/312542
總結
- 上一篇: JavaScript-变量与作用域链
- 下一篇: 安装部署VMware vSphere 5