java 的两道试题

来源:百度知道 编辑:UC知道 时间:2024/05/24 11:34:56
写出下面程序的运行结果
1、 import java.io.*;
public class abc
{ public static void main(String args[ ])
{ AB s = new AB("Hello!","I love JAVA.");
System.out.println(s.toString( ));
}
}
class AB {
String s1;
String s2;
AB( String str1 , String str2 )
{ s1 = str1; s2 = str2; }
public String toString( )
{ return s1+s2;}
}
程序的运行结果是:

2、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';
}

自己动手,才能丰衣足食。

要夺自己猜测、练习、并借助IDE验证自己的想法和结果。

ANSWER:
1、Hello!I love JAVA.
2、good and gbc(局部变量的改变、基本类型和非、引用)

别开了...