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