instance - What would happen if an object is created in non-static method of class in java? -


class data {     int x = 20; // instance variable      public void show() // non-static method     {         data d1 = new data(); // object of same class data         int x = 10;         system.out.println(x); // local x         system.out.println(d1.x);// instance variable x     }      public static void main(string... args) {         data d = new data();         d.show(); // "10 20"     } } 

so question when object created in show() namely 'd1' , must have own set of data members , must have allocated new stack show() method , in return should create new object , cycle should go on , stack-overflow occurs?? working fine??

data d1=new data();  

this statement not allocate new stack show(). show()'s stack allocated when gets called, example, when gets called in main.


Comments

Popular posts from this blog

Capture and play voice with Asterisk ARI -

java - Why database contraints in HSQLDB are only checked during a commit when using transactions in Hibernate? -

visual studio - Installing Packages through Nuget - "Central Directory corrupt" -