I have two instance variables, head and tail. There is a line in the code:
head = tail = new Node<E>();
Does this mean that there are two instances, head and tail, of the Node class? I am very confused here.
It just means:
tail = new Node<E>(); head = tail;
So, there are 2 links ( head and tail ) pointing to the same instance of Node<E> .
head
tail
Node<E>
This means that there are two references to ONE Node object.
Node
Line tail = new Node<E>(); actually returns a value (in this case, an object reference) equal to the assigned value.
tail = new Node<E>();
No, there is only one instance of Node<E> , but both head and tail refer to it, so you have two reference variables pointing to the same object.
Only one instance of Node . Both head and tail refer to the same instance.
No, of course not.
Here's what happens in this code, in sequence.
2 head and tail links are assigned to the same Node instance.
Only one object is created, the head and tail refer to the same object.
object1=object2 ;
Here Object1 one refrence to other means just object2 copies all the addresses into the link object1
Just object2 is copied to object1