class Person
{
private String name;
private int age;
public Person(String name,int age)
{
this.name=name;
this.age=age;
}
public void change(Person p)
{
p.name="李四";
p.age=30;
}
public void print()
{
System.out.println("姓名:"+this.name);
System.out.println("年龄:"+this.age);
}
}
public class JavaDemo02
{
public static void main(String args[])
{
Person p1=new Person("张三",33);
p1.change(p1);
p1.print();
}
}
change方法中传入p1对象,为什么打印的却是p呢?不理解
{
private String name;
private int age;
public Person(String name,int age)
{
this.name=name;
this.age=age;
}
public void change(Person p)
{
p.name="李四";
p.age=30;
}
public void print()
{
System.out.println("姓名:"+this.name);
System.out.println("年龄:"+this.age);
}
}
public class JavaDemo02
{
public static void main(String args[])
{
Person p1=new Person("张三",33);
p1.change(p1);
p1.print();
}
}
change方法中传入p1对象,为什么打印的却是p呢?不理解