public class Example { /**
 * @param args
 */
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';}}

解决方案 »

  1.   

    good and gbc  String它是传引用的,后一个是传值的。
      

  2.   

    你这么理解,ex.change(ex.str,ex.ch);// 传给change方法的ex.str和ex.ch都是“指针”reference
      

  3.   

    dyw8021(中原浪子)结果是对的。但是解释好像反了吧?change(String str,char ch[])中 str是值传递,change函数有自己的作用域
    str在change函数外部(域范围外)值不会改变。
    ch[]是地址传递,只要有一处改变,因为地址值变化了,所以在change函数外ch[]的值也跟着变化
      

  4.   

    String是不可变对象,所以值是不变的
    而char[]显然不在此列,所以值改变了