The program outputs:
Node 0: 223 new value: 17
The setter
setValue() changes the value in a Node
and getValue() retrieves the value in a Node.
Here is a program that constructs three nodes and three reference variables to point to them:
public class NodeTester
{
public static void main ( String[] args )
{
Node node0 = new Node( 223 );
Node node1 = new Node( 493 );
Node node2 = new Node( 717 );
System.out.println("Node 0: " + node0 + ", Node 1: " + node1 + ", Node 2: " + node2);
node0.setValue( -34 );
node2.setValue( node1.getValue() );
System.out.println("After changes: ");
System.out.println("Node 0: " + node0 + ", Node 1: " + node1 + ", Node 2: " + node2);
}
}
The three reference variables
node0, node1, and node2
each points to a Node.
Each Node holds a value.
The Nodes are not linked, yet.
What is the output of the program?