我有 3 个类,它们相互继承如下:
A
↳
B
↳
C
在每个类中,我都有以下方法:
protected void foo() {
...
}
在课堂内C我想foo从课堂上打电话A而不打电话:fooB
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类是一个单元测试类,它有一些修改。foo里面的方法B做了一些我们不想要的事情,所以我们在里面覆盖它C。但是foo在课堂A上很有用,需要调用。