//输出的结果是?????????
//The answer is good and gbc
//The answer is good and gbc
public class Example {
String str=new String("good");//new 一下分配一次内存空间,在new就又的分配一次内存空间
char []ch={'a','b','c'};
public static void main(String [] args){
Example ex=new Example();//
ex.change(ex.str,ex.ch);//在这个过程中只调用了全局变量str
System.out.print(ex.str+" and ");
System.out.print(ex.ch);
}
public void change(String str ,char ch[]){
str=new String("test ok");//这个str相当于局部变量,在运行完之后,这个内存空间就要被释放
ch[0]='g';//而这个仍然为全局变量,因为没有new
}
}
//输出的结果是?????????
//The answer is good and gbc