a test program | what's happening | object diagram | print out |
---|---|---|---|
Point a; |
a Point object reference variable named "a" is declared |
||
Point b; |
a Point object reference variable named "b" is declared |
||
a = new Point("first",0,0); System.out.println(a); |
an instance of the Point class is created with the values "first", 0, and 0. Then, object reference variable a is assigned to the object. |
Point first is located at (0,0). | |
b = a; System.out.println(a); System.out.println(b); |
object reference variable b is assigned the value of object referece variable a, which is the object to which it points. |
Point first is located at (0,0). Point first is located at (0,0). |
|
a.setX(4); System.out.println(a); System.out.println(b); |
setX(), with argument 4, is called on the object to which object reference variable a points. |
Point first is located at(4,0). Point first is located at(4,0). |
|
b.setY(5); System.out.println(a); System.out.println(b); |
setY(), with argument 5, is called on the object to which object reference variable b points.+ |
Point first is located at(4,5). Point first is located at(4,5). |
|
a = new Point("second",-3,-8); System.out.println(a); System.out.println(b); |
an instance of the Point class is created with the values "second", -3, and -8. Then, object reference variable a is assigned to the object. |
Point second is located at(-3,-8). Point first is located at(4,5). |
|
Point temp = a; System.out.println(a); System.out.println(b); System.out.println(temp); |
a Point object reference variable named "temp" is declared and assigned the value of object reference variable a; |
Point second is located at(-3,-8). Point first is located at(4,5). Point second is located at(-3,-8). |
|
a = b; System.out.println(a); System.out.println(b); System.out.println(temp); |
object reference a is assigned the value of object reference b. |
Point first is located at(4,5). Point first is located at(4,5). Point second is located at(-3,-8). |
|
b = temp; System.out.println(a); System.out.println(b); System.out.println(temp); |
object reference b is assigned the value of object reference temp. |
Point first is located at(4,5). Point second is located at(-3,-8). Point second is located at(-3,-8). |
|
temp = null; System.out.println(a); System.out.println(b); |
the object reference temp is assigned the value of null. |
Point first is located at(4,5). Point second is located at(-3,-8). |
|
a.setY(b.getY()); System.out.println(a); System.out.println(b); |
setY(), with argument of getY() called on the object that object reference variable b points to, is called on the object that object reference variable a points to. |
Point first is located at(4,-8). Point second is located at(-3,-8). |
|
a = temp; System.out.println(b); |
object reference variable a is assigned the value of object reference variable temp. |
Point second is located at(-3,-8). | |
System.out.println(b); |
since there is an object to which no object reference variables point, that object will be deallocated during garbage collection, and no more object reference variable may point to it. |
Point second is located at(-3,-8). |