One of my professor has given us a few practice questions for an exam, and one of the questions is something like the below (psuedocode):
a.setColor(blue);
b
Assuming you've already created two objects, and made variables a
and b
refer to them, you've initially got something like this.
a --> [ white ] b --> [ white ]
Your first two lines change the colours of the objects, to give you
a --> [ blue ] b --> [ red ]
Then, you point the variable a
to the object referred to by b
, so that they both refer to the same object. You now have
[ blue ] b --> [ red ] <-- a
Then you change the colour of the object referred to by b
.
[ blue ] b --> [ purple ] <-- a
Lastly, the line b=a;
does nothing, because b
already refers to the same object as a
.