日期:2014-05-20  浏览次数:20608 次

对象引用型参数的传递问题
弱弱的问一下各位大大,今天小弟我练习java遇到一个问题   现在把代码贴出来给各位大大看看   望能帮我解答   小弟不胜感激

public   class   Example2   {

//自定义方法来改变参数
public   static   void   change(String   str,char   ch[])
{
str= "change ";
ch[0]= 'C ';               //将字符 'c '赋值给字符数组的第一个元素
}
public   static   void   main(String[]   args)   {
//   TODO   Auto-generated   method   stub
                //创建并初始化字符串对象,及字符数组对象
String   s   =   new   String( "world ");
char   ch[]   =   { 'h ', 'e ', 'l ', 'l ', 'o '};

//调用change()方法
change(s,ch);
System.out.println(s+ "   and   "+ch);
}

}

得出的结果是:world   and   [C@35ce36

我做这题结果应为:world   and   Cello

希望各位能帮我解答一下


------解决方案--------------------
System.out.println(s+ " and "+ch);
ch是一个字符数组,不能直接println, 试试 System.out.println(s+ " and "+new String(ch));