Dear Reader,
First of all, you need to make your data members private. Its not compulsory but a good design technique.
Next, make setter and getter methods for each of the data members.
eg.
With that in place, you need to now understand that the NumberNode class does not do anything important except hold information.
You need to have another driver sort of class, or should I say a List (LinkedList or anything similar) to make use of this NumberNode class.
The driver class keeps a reference to a root NumberNode object. And this root reference holds a refernce to another NumberNode object and this ... so you get what I am trying to say.
A kind of linked list is maintained where each node (NumberNode in this case) holds information to the next node.
The driver class is responsible for inserting and deleting nodes from this list and performing other manipulations.
The driver class while performing the above operations, calls the getNext() and setNext() (and other setter and getter methods) of the NumberNode class.
ok how does the node know that when ".next" is called, to go to the next
node in the list?
So, the NumberNode object does not need to know when to go to the next. Infact, its the driver class that keeps track of this information,
with the help of the getter and setter methods. Do you understand what I am trying to say?