<分区>
在下面的示例中,如何从 C
访问类 A
的方法 method()
?
class A {
public void method() { }
}
class B extends A{
public void method() { }
}
class C extends B{
public void method() { }
void test() {
method(); // C.method()
super.method(); // B.method()
C.super.method(); // B.method()
B.super.method(); // ERROR <- What I want to know
}
}
我得到的错误是
No enclosing instance of the type B is accessible in scope
回答:不,这是不可能的。 Java不允许。 Similar question .