• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Inner Class Doubts

 
Ranch Hand
Posts: 344
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


output:
Prints: A0B0A1B1A1B2

The output generated by the above pgm is very confusing. Can anyone explain it?
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
new A().new B(); // 2
A a1 = new A();
a1.new B(); // 3
a1.new B(); // 4

Output after line 2: A0B0 (name=A0, inname = B0, counter = 1, inCnt = 1)
Output after line 3: A0B0A1B1 (name = A1, inname = B1, counter = 2, inCnt = 1)
Before line 4: (name=A1, inname=B2, counter = 2, inCnt=2)
Output after line 4: A0B0A1B1A1B2 (name=A1, inname=B2, counter = 2, inCnt=3)

Hope this helps.
 
My first bit of advice is that if you are going to be a mime, you shouldn't talk. Even the tiny ad is nodding:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic