my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inner Class - K&B - Page 483 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 Class - K&B - Page 483" Watch "Inner Class - K&B - Page 483" New topic
Author

Inner Class - K&B - Page 483

suriya indu
Greenhorn

Joined: Jan 22, 2004
Posts: 2
Here is the Code from K&B's inner class section (Page 483)

I am not able to under stand the syntax (new Bar(){}).go(); used to invoke the inner class method. My understanding is either (new Bar()).go();
or 1. Bar in = new Bar(); 2. in.go() is the right way to invoke the method go() of the inner class. Confusion is the {} braces after the new Bar(){}.
Can any one explain me this please. My Head is spinning with inner class concept
[ March 06, 2004: Message edited by: suriya indu ]
[ March 06, 2004: Message edited by: suriya indu ]
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
The line you mention: (new Bar(){}).go(); creates an anonymous inner class that extends the inner class Bar. It is no different than just writing (new Bar()).go(); since the go method is not overriden. This may make more sense to you:

[ March 06, 2004: Message edited by: Michael Morris ]

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Suresh Thota
Ranch Hand

Joined: Sep 24, 2003
Posts: 152
Hi Suriya,
Please check this.
http://www.coderanch.com/t/241051/java-programmer-SCJP/certification/InnerClass-Ch-SierraBates
There is a previous discussion about the above question.
Cheers
-Suresh


SCJP 1.6
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Inner Class - K&B - Page 483
 
Similar Threads
Doubt in Nested Inner Class
Nested classes
Inner Classes
InnerClass question from Ch8 SierraBates
Inner Classes Mock question doubt 3