I am confused about how object references work and was wondering if someone could help. Below is some example code which is supposed to deQueue a Queue based on a linked list for the general case:
Object head = listHead.datum;
listHead = listHead.next;
return head;
My understanding is that when you have a primitive variable the actual value is stored is assigned to it, but if the variable is an object then a reference to an object is stored in there. So in the above code a reference to listHead.datum is stored in head, but then the reference stored in listHead is changed to be listHead.next. When it comes time to return the Object called head I would have thought that it would follow it's assigned reference i.e. go to listHead (which now refers to a different place) and then to datum.
The above code should return the head of the Queue but following my logic it will return the second in the queue. Where am I going wrong?