• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Inner Class - K&B - Page 483

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Suriya,
Please check this.
https://coderanch.com/t/241051/java-programmer-SCJP/certification/InnerClass-Ch-SierraBates
There is a previous discussion about the above question.
Cheers
-Suresh
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic