码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2018-03-21 11:38:18      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:分享   程序   []   tps   coder   code   body   item   pos   

来源于: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

技术分享图片


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

标签:分享   程序   []   tps   coder   code   body   item   pos   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!