开发者

Multi-level inheritance: Calling a method only ONE level higher from subclass

Basically, I have 3 classes

开发者_运维知识库class abstract A{}
   protected aMethod(){}

class abstract B extends A{
   protected aMethod(){}
}

class C extends B{
  // How do I call B.aMethod() from here? As super.aMethod() 
  // would call A.aMethod()?
}

See the code. I want to call a method one class higher that the lowest level. But calling super.aMethod() would return the root class implementation?

EDIT: Turns out super does just go one level higher, god knows what I was trying... Rookie mistake, apologies all!


super.aMethod() would do exactly what you want.


Actually calling super.aMethod() from C, should call aMethod() in B and not in A.


super.aMethod()

should work fine if B implements the method.

Also, just as a note on your tag, multiple-inheritance speaks towards "extending" more than one base class, for example:

public C extends B, A { ... } // WRONG SYNTAX!

which is not supported by Java.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜