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

Oracle Certified Foundations Associate Java Certification Questions and Discussion
1Z0-811

Moderator: admin

Post Reply
nick12345
Posts: 17
Joined: Fri Aug 13, 2021 12:43 pm
Contact:

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

Post 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);
    }
}

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

Yes, node is an instance variable of type Node.
It is a common strategy while creating a Linked list.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests