Page 1 of 1

About Question com.enthuware.jfcja.v8.2.402 :

Posted: Tue Nov 16, 2021 4:29 am
by nick12345
Hello,

I don't understand what is Node node; in this code. Is this an instance variable of type Node?
But why should have an object an instance variable of the same type as the object itself? :?

Code: Select all

class Node{
    int id;
    Node node;
    public static void main(String[] args) {
       Node n =  new Node();
       System.out.println(n.id);
       System.out.println(n.node.id);
    }
}

Re: About Question com.enthuware.jfcja.v8.2.402 :

Posted: Tue Nov 16, 2021 8:58 am
by admin
Yes, node is an instance variable of type Node.
It is a common strategy while creating a Linked list.