关于java中的值传递与引用传递遇到的问题

来源于:https://www.nowcoder.com/test/question/done?tid=14302398&qid=25373#summary

下列java程序的输出结果为____。

 1 public class Example{
 2     String str=new String("hello");
 3     char[]ch={'a','b'};
 4     public static void main(String args[]){
 5         Example ex=new Example();
 6         ex.change(ex.str,ex.ch);
 7         System.out.print(ex.str+" and ");
 8         System.out.print(ex.ch);
 9     }
10     public void change(String str,char ch[]){
11         str="test ok";
12         ch[0]='c';
13     }
14 }

正确答案: B   你的答案: E (错误)

hello and ab
hello and cb
hello and a
test ok and ab
test ok and cb
test ok and c



原文地址:https://www.cnblogs.com/lucong-white/p/8615154.html