一个对象引用的问题
class point{
int x,y;
void setXY(int m,int n)
{
x=m;
y=n;
}
}
public class application4_8
{
public static void main(String args[])
{
point p1,p2,p3;
p1=new point();
p2=new point();
System.out.println("p1的引用:"+p1);
System.out.println("p2的引用:"+p2);
p1.setXY(1111,2222);
p2.setXY(-100,-200);
System.out.println("p1的x,y坐标:"+p1.x+"."+p1.y);
System.out.println("p2的x,y坐标:"+p2.x+"."+p2.y);
p2=p1;
System.out.println("p1的x,y坐标:"+p1.x+"."+p1.y);
System.out.println("p2的x,y坐标:"+p2.x+"."+p2.y);
p3=p2;
p3.x=10;
p3.y=60;
System.out.println("p1的x,y坐标:"+p1.x+"."+p1.y);
}
}
为什么最后p1的坐标是10,60,按道理说p2赋值给p3,应该用p2的值代替P3,则p1的坐标应该不变啊,怎么会变成10,60,不懂,请大神指教!!