Yes. All objects are accessed through a reference, and node0.next could
contain such a reference.
Here is another program:
public class NodeTester
{
public static void main ( String[] args )
{
Node node0 = new Node( 223 );
Node node1 = new Node( 493 );
System.out.println("Node 0: " + node0 + ", Node 1: " + node1 );
node0.setNext( node1 );
System.out.println("Node 0: " + node0 + ", Node 1: " + node0.getNext() );
}
}
Now there are two nodes.
The next member of node0 has been set
to contain a reference to node1.
In other words,
node1
and
node0.getNext()
are identical references to the same object. Here is a picture:
What is printed by these statements from the program?
System.out.println("Node 0: " + node0 + ", Node 1: " + node1 );
node0.setNext( node1 );
System.out.println("Node 0: " + node0 + ", Node 1: " + node0.getNext() );
(Recall that the toString() method is automatically invoked.)