In part 1 of this series I argued that the spec is broken, now I'll show the first example where the reference implementation does not implement the spec.
package p1;
public class A
{
{ foo(); }
public void foo() {
System.out.println("A.foo");
}
public static void main(String[] args) {
new p3.C();
}
}
package p2;
public class B extends p1.A
{
{ foo(); }
void foo() {
System.out.println("B.foo");
}
}
package p3;
public class C extends p2.B
{
void foo() {
System.out.println("C.foo");
}
}
(If you want to compile this with javac you'll need to first compile it with a version of A that does not have a public foo method and then change A and just recompile A.)
Now the question is does C.foo override B.foo? According to the spec it does not, but when you compile this with javac from JDK 7 (because the class file version needs to be 51 to get the new behavior) and run it you get:
C.foo
C.foo
So C.foo overrides both A.foo and B.foo.