• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Nonstatic nested class execution doubt

 
Shiva Mohan
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Output is A1B0A0B1A2B2 .Starting itself I am getting trouble that getting value is A0.
How the starting value A1 is coming. It might end up like silly doubt. But I couldn�t figure it out.
 
Shiva Mohan
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured it out. Ppp() is called first time by this ppp myA=new ppp();
Then calling m1()���
Thanks.
 
prarthana reddy
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shiva,
I could understand the output A1B0 ( the first part of answer) . Could you please explain the remaining part of the answer ?I also have one more doubt.
new ppp().new B() ( //line 4 ) . Will this create an instance of B alone or ppp too ?

Thanks in advance
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
new ppp().new B() ( //line 4 ) . Will this create an instance of B alone or ppp too ?



Class B is an inner class. When you create an instance of B, it requires an instance of Outer class here ppp, so both objects will be created. writing simply new B() in main method is wrong.

Naseem
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic