有如下代码:public class Test{ public static void main(String args[]) { String str = new String("World"); char ch[] = {'H','e','l','l','o'}; change(str,ch); System.out.println(str + "and" + ch); } public static void change(String str, char ch[]) { str = "Changed"; ch[0] = ' C'; }}运行后输出的结果是:
A: Changed and Cello
B: World and Cello
C: World and CelloChanged and Hello
D: World and Hello
A: Changed and Cello
B: World and Cello
C: World and CelloChanged and Hello
D: World and Hello
举一反三
- 有如下代码:public class Test4{ public static void main(String args[]) { String str = new String("New"); char ch[] = {'B', 'e'}; change(str,ch); System.out.println(str + "," + new String(ch)); } public static void change(String str, char ch[]) { str = "Old"; ch[0] = 'H'; }}运行后输出的结果是? A: New,Be B: New,He C: Old,He D: Old,Be
- 有如下代码: public class Test{ public static void main(String args[]) { String str = new String("World"); char ch[] = {'H','e','l','l','o'}; change(str,ch); System.out.println(str + "and" + ch); } public static void change(String str, char ch[]) { str = "Changed"; ch[0] = 'C'; } } 运行后输出的结果是:
- 程序运行的结果是: good and gbc。( ) public class Example{ 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 “); Sytem.out.print(ex.ch); } public void change(String str,char ch[]){ str=”test ok”; ch[0]=’g'; } }
- 对于下列代码: public class Example{ String str=new String("java"); char ch[]={'d','b','c'}; public static void main(String args[]){ Example ex=new Example(); ex.change(ex.str,ex.ch); System.out.println(ex.str+" and "+ex.ch[0]); } public void change(String str,char ch[]){ str="world";ch[0]= 'b'; } } 输出结果是: ( ) A: javaandd B: javaand C: javaandc D: javaanda
- 给定以下代码,程序的运行结果是 ()public class Example {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';}} A: goodandabc B: goodandgbc C: test okandabc D: test okandgbc