• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Inner Classes Mock question doubt 3

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

This is a question from K & B Book, Chapter Inner classes, Page 669



See the explanation of Option c..

I know the correct option is C...But I feel there is something wrong in its explantion..

It tells it creates bar and then finally creates instance of anonymous subclass of bar..??

I think only one instance is created and that is instance of anonymous subclass of bar

am i correct..??

BOTTOM LINE :
when makeBar() method is invoked, it creates an instance of anonymous subclass of bar, thus prints "bar"
and then it invokes method go() on the newly created instance, so "hi" is printed.

Regards,
Hardik.S.Raja
[ May 04, 2007: Message edited by: Hardik Raja ]
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
override the method go, inside the anonymous class and see the result:


Output:
...
...
Its my life


Thanks,
cmbhatt
 
Hardik Raja
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok I got my answer...

It means only one instance is created that of anonymous subclass of Bar..

Thanks...
 
God is a comedian playing for an audience that is afraid to laugh - Voltair. tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic