Practical Java笔记一:区别引用类型和原始类型

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);

}

}

你可能感兴趣的:(Practical Java)