我不明白为什么下面的示例会抛出 IllegalAccessError 异常。foo()中的方法Parent不能被 继承Child,因为它是私有的。但尝试调用默认方法foo()会导致异常。
public class Parent {
private void foo() {
System.out.println("Parent-foo");
}
}
interface Boo {
default void foo() {
System.out.println("Boo-foo");
}
}
class Child extends Parent implements Boo {
public static void main(String[] args) {
new Child().foo(); // runtime IllegalAccessError;
}
}
Run Code Online (Sandbox Code Playgroud)