public class User {
int id;
String name;
String pwd;
public User(int id, String name) {
this.id = id;
this.name = name;
}
//测试1
public void testParameterTranser01(User u) {
u.name = "张三";
}
public void testParameterTranser02(User u) {
u = new User(123, "李四");
}
//主程序
public static void main(String[] args) {
User u1 = new User(123, "李四");
System.out.println(u1.name);
u1.testParameterTranser01(u1); //u1的地址复制给了形参u,在形参的地址处改变了内容,把原来的内容改变
System.out.println(u1.name);
u1.testParameterTranser02(u1); //u1的地址复制给了形参u,但是方法里开辟了一个新的空间地址又给了形参
System.out.println(u1.name);
}
}
李四
张三
张三