<分区>
Possible Duplicate:
Why is super.super.method(); not allowed in Java?
我有 3 个类,它们相互继承如下:
A
↳
B
↳
C
在每个类中我都有以下方法:
protected void foo() {
...
}
在 C
类中 我想从 A
类中调用 foo
而不是在 B 中调用
:foo
protected void foo() {
// This doesn't work, I get the following compile time error:
// Constructor call must be the first statement in a constructor
super().super().foo();
}
编辑
一些上下文信息:
B 类是我们实际使用的类。 C类是一个单元测试类,它有一些修改。 B
中的 foo
方法做了一些我们不想做的事情,所以我们在 C
中重写了它。但是 A
类中的 foo
很有用,需要调用。