public class TestMain {
public static void main(String[] args) {
Person p1 = new Person(10);
modify(p1); //修改p1引用的对象
System.out.println(p1);
}
public static void modify(Person p){ //使用此函数修改引用的指向
p = new Person(20);
}
}
class Person { //实验用类
public int age;
@Override
public String toString() {
return "Person [age=" + age + "]";
}
public Person(int age) {
this.age = age;
}
}
输出结果什么是 Person [age=10]
不应该是Person [age = 20] 么?
富国沪深
杨魅力
慕容3067478
慕雪6442864
白板的微信
随时随地看视频慕课网APP
相关分类