• Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple Inheritance Question  RSS feed

 
Nicholas d'Hondt
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I'm just a little unclear about this, but how would I call methods from the 'top' of an inheritance chain? I say 'top' because Object is the top

E.g.:


Assuming that BClass.myMethod() completely overrides AClass.myMethod() (so that there is no call to super.myMethod() in BClass.myMethod()) How can I call AClass.myMethod() from CClass.myMethod()?
 
Paul Clapham
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer: You can't call that method directly from your CClass class. That's the inheritance part of the question; a class only knows about the class it extends and not about anything higher in the inheritance chain.

From the design point of view: if you need to call AClass.myMethod from CClass, that means your inheritance hierarchy is designed incorrectly.
 
Nicholas d'Hondt
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, that's what I assumed, but I wanted to make sure.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use super.myMethod() as part of the method in the subclass. It is a lot easier to understand if the method returns something
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!