class ReferencesTest {
public static void main(String[] arguments) {
Point pt1, pt2;
pt1 = new Point(100, 100);
pt2 = pt1; pt1.x = 200;
pt1.y = 200;
System.out.println("Point1: " + pt1.x + ", " + pt1.y);
System.out.println("Point2: " + pt2.x + ", " + pt2.y);
}
}
答案:Point1: 200, 200
Point2: 200, 200
为什么不是Point1: 200, 200
Point2: 100,100呢,
Point pt1, pt2;
pt1 = new Point(100, 100);
pt2 = pt1; pt1.x = 200;
pt1.y = 200;
System.out.println("Point1: " + pt1.x + ", " + pt1.y);
System.out.println("Point2: " + pt2.x + ", " + pt2.y);
等于Point pt1, pt2;
pt1 = new Point(100, 100);
pt1.x = 200;
pt1.y = 200;
pt2 = pt1;
System.out.println("Point1: " + pt1.x + ", " + pt1.y);
System.out.println("Point2: " + pt2.x + ", " + pt2.y);么?????
public static void main(String[] arguments) {
Point pt1, pt2;
pt1 = new Point(100, 100);
pt2 = pt1; pt1.x = 200;
pt1.y = 200;
System.out.println("Point1: " + pt1.x + ", " + pt1.y);
System.out.println("Point2: " + pt2.x + ", " + pt2.y);
}
}
答案:Point1: 200, 200
Point2: 200, 200
为什么不是Point1: 200, 200
Point2: 100,100呢,
Point pt1, pt2;
pt1 = new Point(100, 100);
pt2 = pt1; pt1.x = 200;
pt1.y = 200;
System.out.println("Point1: " + pt1.x + ", " + pt1.y);
System.out.println("Point2: " + pt2.x + ", " + pt2.y);
等于Point pt1, pt2;
pt1 = new Point(100, 100);
pt1.x = 200;
pt1.y = 200;
pt2 = pt1;
System.out.println("Point1: " + pt1.x + ", " + pt1.y);
System.out.println("Point2: " + pt2.x + ", " + pt2.y);么?????
pt1 = new Point(100, 100);// 给pt1分配内存空间
pt2 = pt1;//pt2的地址=pt1的地