I've been studying for coding interviews and I have a question about java object assignments.
say I have a Node class and I create three instances.
Node a = new Node(1);
Node b = new Node(2);
Node c = new Node(3);
Now let's say I do an assignmet
a = b;
At this point I know that any change I make to the properties of Node a or b will result in a change to both a and b because this is a shallow copy.
i.e.
a.data = 99 //then b.data will become 99
or
b.data = 99 //then a.data will become 99
however if I do
b = c;
now any changes I make to the property of Node b won't have any affect on Node a.
b.data = 99;//then b.data will become 99 and c.data will become 99 but a.data will not change
I don't understand this behavior. I understand that Node b is assigned the value of Node c's address, but why doesn't this affect Node a?