Why is interface default method shadowed by parent private method?

55 Views Asked by At

I don't understand why an IllegalAccessError exception is thrown from the example below. The method foo() in Parent cannot be inherited by Child, because it is private. But trying to call the default method foo() leads to the exception.

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;
    }
}
0

There are 0 best solutions below