public class Example{
String str=new String("hello");
//char[]ch={'a','b'};
public static void main(String args[]){
Example ex=new Example();
//ex.change(ex.str,ex.ch);
//ex.change();
ex.change(ex.str);
System.out.print(ex.str+" and ");
//System.out.print(ex.ch);
}
//public void change(String str,char ch[]){
public void change(String str){
//public void change(){
System.out.println("局部变量参数值(局部值等于全局值)"+str);
str="test ok";
System.out.println("局部变量参数值2(变了)"+str);
System.out.println("全局参数(没变)"+this.str);
//ch[0]='c';
}
}
java值传递与引用传递小例子
最新推荐文章于 2022-09-27 19:00:00 发布