• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Nonstatic nested class execution doubt

 
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I figured it out. Ppp() is called first time by this ppp myA=new ppp();
Then calling m1()���
Thanks.
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic