File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Inner Class - K&B - Page 483" Watch "Inner Class - K&B - Page 483" New topic

Inner Class - K&B - Page 483

suriya indu

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.
There is a previous discussion about the above question.

SCJP 1.6
I agree. Here's the link:
subject: Inner Class - K&B - Page 483
jQuery in Action, 3rd edition