• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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
 
Time is mother nature's way of keeping everything from happening at once. And this is a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic