how to invoke a method a few levels higher in the inheritance tree?

if class C extends class B
and
class B extends class A
and
class A has a public method called add() which is overridden in both child classes B and C.How can the version A of method add() be invoked from class C?
thanks

Try to write down your own small code because of that you understood the concept easily.

Life is easy because we write the source code.....

kevinn lee
Ranch Hand

Joined: Feb 15, 2010
Posts: 87

posted Apr 11, 2010 02:57:21

0

thanks
but this is not what I meant.how to invoke version A of add() from class C without creating an instance of A?
say for example if I want to have a method in C that has a line " System.out.print(/*A s method add()*/);"
what Im asking is what should come in between /*...*/?
thanks

It is quite possible and I won't tell you how to do that. The reason is that a subclass "is-a" superclass; if there is a method foo() which does something in the superclass, and something different again in the superclass of that superclass, then calling super.super.foo() breaches the principle that a class behaves as if it "is-a" superclass. (and the compiler definitely won't like super.super).

So I won't tell you how it is done, just as I wouldn't tell somebody else here.