Meaningless Drivel is fun!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inner Classes Mock question doubt  3 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Inner Classes Mock question doubt  3" Watch "Inner Classes Mock question doubt  3" New topic
Author

Inner Classes Mock question doubt 3

Hardik Raja
Ranch Hand

Joined: Feb 07, 2006
Posts: 117
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 ]
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
override the method go, inside the anonymous class and see the result:


Output:
...
...
Its my life


Thanks,
cmbhatt


cmbhatt
Hardik Raja
Ranch Hand

Joined: Feb 07, 2006
Posts: 117
Ok I got my answer...

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

Thanks...
 
Consider Paul's rocket mass heater.
 
subject: Inner Classes Mock question doubt 3
 
Similar Threads
Doubt in Nested Inner Class
Nested classes
ch8 K&B 1.4 qno:8
InnerClass question from Ch8 SierraBates
K&B chapter 8 Self Test Q 8