C:\JavaSource> javac Node.java NodeTester.java C:\JavaSource> java NodeTester Node 0: 223, Node 1: 493, Node 2: 717 After changes: Node 0: -34, Node 1: 493, Node 2: 493 C:\JavaSource>
next
Examine class Node
again:
public class Node { private int value; private Node next; public Node ( int val ) { value = val; next = null; } public int getValue() { return value; } public Node getNext() { return next; } public void setValue( int val ) { value = val; } public void setNext( Node nxt ) { next = nxt; } public String toString() { return "" + value; } }
Say that a main
program created a Node
using Node node0 = new Node( 223 );
next
is declared to be of type Node
.
This means that next
can contain a reference to an object of type Node
.
In the picture, the slash in next
represents null
.
If there were another Node
object somewhere, could node0.next
point to it?