public class MyTest {
String str = new String("good");
char[] ch = { 'a', 'b', 'c' };
public static void main(String[] args) {
MyTest ex = new MyTest();
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';
}
}
调用change方法,str只是改了局部变量的内容,不影响外部值,因此还是good
数组改变了同一个引用地址的内容,所以为gbc