//输出的结果是?????????
//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

相关文章:

  • 2021-05-23
  • 2021-04-25
  • 2022-01-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-25
  • 2021-08-10
猜你喜欢
  • 2022-01-05
  • 2021-11-30
  • 2021-05-27
  • 2022-01-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案