oop - can we access non-static class from main() method in java? -


in if make node class non-static , main method able access it.

class linkedlist  {     node head;    static class node {     int data;     node next;     node(int d)  { data = d;  next=null; } // constructor }   public static void main(string[] args) { ..............} } 

yes, can access node class main method, if instantiate object class. can that:

class linkedlist {      node head;      class node {         int data;         node next;         node(int d)  { data = d;  next=null; } // constructor     }       public static void main(string[] args) {         //instantiate object         linkedlist.node node = new linkedlist().new node(0);     } } 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -