Reputation: 161
I have two instance variables, head and tail. In the code there's a line:
head = tail = new Node<E>();
Does this mean that there are two instances, head and tail, of class Node? I'm quite confused here.
Upvotes: 4
Views: 3580
Reputation: 1
object1=object2 ;
Here Object1 one refrence to other means simply object2 is copied all addresses to object1 reference
Simply object2 is copied into object1
Upvotes: 0
Reputation: 159754
The 2 references head
and tail
are both assigned to the same single instance of Node
.
Upvotes: 1
Reputation: 25950
It simply means:
tail = new Node<E>();
head = tail;
So there are 2 references (head
and tail
) pointing to the same Node<E>
instance.
Upvotes: 13
Reputation: 291
Only one object is created, head and tail both references the same object.
Upvotes: 1
Reputation: 7519
No certainly not.
Here's what's happening in this code, in sequence.
Upvotes: 2
Reputation: 405735
No, there's only one instance of Node<E>
created, but both head
and tail
refer to it, so you have two reference variables that point to the same object.
Upvotes: 3
Reputation: 32323
This means there are TWO references to ONE Object Node
.
The line tail = new Node<E>();
actually returns a value (in this case an object reference) equal to the assigned value.
Upvotes: 4
Reputation: 66637
Only one instance of Node
. Both head
and tail
references pointing to same instance.
Upvotes: 2