luohzzz

导航

值传递、引用传递

public class oopDemo4 {
public static void main(String[] args) {
//java属于值传递
int a =1;

System.out.println(a);

change(a);

System.out.println(a);//这里输出a还是等于1
}
public static void change(int a){//(int a)是一个形参,java属于值传递

a = 10;
return;
}
}


public class oopDemo5 {
public static void main(String[] args) {
Perosn perosn = new Perosn();

System.out.println(perosn.name);

change(perosn);

System.out.println(perosn.name);
}
public static void change(Perosn perosn){
perosn.name = "luo";
}
}
class Perosn{
String name;
}

posted on 2021-04-29 17:48  luohzzz  阅读(21)  评论(0编辑  收藏  举报