public class RefereceAndPrimit {
public static void main(String[] args) {
int a = 1;
int b = 2;
Point x = new Point(0,0);
Point y = new Point(1,1);
System.out.println("a is "+a);
System.out.println("b is "+b);
System.out.println("x is "+x);
System.out.println("y is "+y);
System.out.println("a is "+a);
System.out.println("------------");
a = b;
a++;
x = y; //修改的是object reference而不是object本身,x和y都是指向同一对象,所以对x改变同时也对y改变
x.setLocation(5, 5);
System.out.println("a is "+a);
System.out.println("b is "+b);
System.out.println("x is "+x);
System.out.println("y is "+y);
}
}
转载于:https://www.cnblogs.com/andgoo/archive/2012/03/13/2395202.html