public static void main(String args[]) {
Person person1 = new Person();
person1.setName("1");
Person person2 = new Person();
person2.setName("2");
System.out.println(person2.getName());
person2 = person1;
System.out.println(person2.getName());
person1.setName("11");
System.out.println(person2.getName());
}
Person person1 = new Person();
person1.setName("1");
Person person2 = new Person();
person2.setName("2");
System.out.println(person2.getName()); //输出person2.Name 2
person2 = person1; //把person1的值给person2
System.out.println(person2.getName()); //person2.Name=person1.Name=1
person1.setName("11");
System.out.println(person2.getName());//person2.Name=person1.Name=11
对象是引用类型
person2 = person1;是把person2的引用地址指向penson1的引用地址
person1.setName("11");修改的是他们2个引用的地址所以输出也会是11
灰常感谢!
....................
这个太基础了吧。先自学