Overriding protected methods in Java

Test.java

package a;
import b.B;
public class Test {
    public static void main(String[] v) {
        new A().test();
        new B().test();
    }
}

A.java:

package a;
public class A {
    protected void test() { }
}

B.java:

package b;
public class B extends a.A {
    protected void test() { }
}

Why does new B().test() give an error? Doesn't that break visibility rules?

B.test() is invisible in Test because they're in different packages, and yet it refuses to call the test() in B's superclass which is visible.

Links to the appropriate part of the JLS would be appreciated.

13
задан APerson 3 January 2015 в 16:22
поделиться