I've been learning Java over the past year and I've gotten fairly proficient with data structures, but there's something that's always been on my mind that I've never quite figured out. The following is an example:
public class SList{
private SListNode head;
private int size;
public void insertEnd(Object obj) {
if (head == null) {
head = new SListNode(obj);
} else {
SListNode node = head;
while (node.next != null) {
node = node.next;
}
node.next = new SListNode(obj);
}
size++;
}
Assuming SListNode and the SList constructor have already both been implemented, why is it that the "head" reference changes and has a Node added to its end while there was no declaration like head = node; at the very end of the method? I know this is probably very basic, but I've been looking for a while and there's never been an explanation.