• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Need Help on More Anonymous Classes

 
Ranch Hand
Posts: 330
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello.
In the code below, why is it that the overridden methods method1 and method2 never gets called and the original methods are executed instead? However, changing all the private access modifiers to public access enables the overridden methods to be called instead of the original methods?
Any insights/info is greatly appreciated. Thanks.

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Is it because the methods defined inside the anonymous class are private and can be called within the anonymous class only?? (ie. the methods are not visible in the context where it is defined, since they are private)
Uma.
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
private methods cannot be overridden. In fact, outside of the class in which they are defined, they simply don't exist (and therefore can't be overridden) - even subclasses don't know about them.
Your anonymous class is a subclass. It's redeclaration of the private methods does not override them. Hence the behavior.
 
dennis zined
Ranch Hand
Posts: 330
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got it. Geesh, there's just so many things to keep in mind. Thanks again Steve
 
reply
    Bookmark Topic Watch Topic
  • New Topic