• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic