简单的内存知识,生疏了,为了稳妥又测试了一下……
public class TryCopy {
public static void main(String[] args) {
Point a = new Point(1, 2);
Point b = new Point(3, 4);
Line temp = new Line(a, b);
a.setX(100);
System.out.println(temp.s.x);
}
}
class Line {
Point s;
Point e;
public Line(Point a, Point b) {
this.s = a;
this.e = b;
}
}
class Point {
int x;
int y;
public void setX(int x) {
this.x = x;
}
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
输出结果:
100