I found this JDK bug and want to understand why it happens.
The scenario (taken from the bug report) is very simple: a class declaring a private method, and an interface declaring a public method with the same signature. It compiles without error.
However, when I run this code I am getting IllegalAccessError
interface I {
public void m();
}
class A {
private void m() {
System.out.println("Inside Class A");
}
}
abstract class B extends A implements I {
}
class C extends B {
public void m() {
System.out.println("Inside Class C");
}
}
public class Test {
public static void main(String... args) {
B b = new C();
b.m();
}
}
Please help me understand why this error is there as my code is compiling fine.
Exception in thread "main" java.lang.IllegalAccessError:
tried to access method A.m()V from class Test
at Test.main(Test.java:25)