Issue
I am new in programming.
While I was surfing on the internet I found a code that has this class.
class Node {
private Node link = null;
private int data = 0;
My question is that, what is this "Node" (on the second line) under the class Node{
Is this a variable? What is it called? And what is its purpose?
Solution
In Java a variable is can contain a reference to an object. The pattern you show is common in list nodes: a node contains a value and a reference to the next node.
Let us look at your code:
class Node { // Ok, we are defining a class named Node
private Node link = null; // Ok we have a member reference to another Node object
// and by default it is initialized to null
private int data; // an integer member variable
...
}
Answered By - Serge Ballesta
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.