Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Anonymous inner class

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how can we access overriding method foof()?Is there any way to access this?thanks in advance.





[HENRY: Added Code Tags]
 
author
Posts: 23919
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hemant Khandal wrote:how can we access overriding method foof()?Is there any way to access this?thanks in advance.




Not sure of your issue here. By definition, the overriding method (subclass) is always the method that will be called. It is the super class' method (the method that was overridden) that is no longer accessible. And this is true, even if the subclass is an anonymous inner class.

Henry
 
Marshal
Posts: 75650
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you mean overridden? You can use the super keyword, but only in a non-static context in the subclass.
 
Hemant Khandal
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now I am talking only above code.I want to call overridden method foof() from main().Is it possible ? If yes then please let me know how can we do this?
It's pleasure for me if you add some line as per situation.
This is only for understanding java concepts.
Thanks in advance.
 
Henry Wong
author
Posts: 23919
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hemant Khandal wrote:Now I am talking only above code.I want to call overridden method foof() from main().Is it possible ? If yes then please let me know how can we do this?



From the code, it is *not* possible. The Foo instance is created internal to the go() method. It can't be accessed from the main method.

And this doesn't have anything to do with it being an anonymous inner class, or if the method is overridden or not. The instance is just not accessible to the main method. Period. You will have to modify the go() method to expose it somehow, before the main method can access it.

Henry
 
You get good luck from rubbing the belly of a tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic