The Java Language specification for Java 7 does not contain separate rules for abstract methods, since such an abstract method without a qualified access level default aka package private, like a regular method.
See also 6.6.1. Availability Definition :
An element (class, interface, field or method) of a reference type (class, interface or array) or a constructor of a class type is available only if the type is available and a member or constructor is declared for access:
- If a member or constructor is declared public, access is allowed.
All interface members are implicitly public. - Otherwise, if a member or constructor is declared protected, access is allowed only when one of the following conditions is true:
- Access to a member or constructor comes from a package containing a class in which a protected member or constructor is declared.
- Access is correct as described in §6.6.2.
- Otherwise, if a member or constructor is declared private, access is permitted only when it occurs inside the body of a top-level class (§7.6), which includes the declaration of a member or constructor.
- Otherwise, we say that there is default access, which is only allowed when access occurs from within the package in which the type is declared.
(my emphasis)
Also note that the term "default access" is equivalent to a "closed package", the only "exception" for it are declarations of methods in the interface that are simply always public , and therefore it is not necessary to have a prefix.
Edit:
Since adenoyelle points to his answer , you can override the default abstract method in another package (according to the rules of JLS 8.4.3.1. abstract Methods ), so you can consider them protected , but a quick JLS scan does not seem to do this explicitly.
Edit 2:
I just tested it. It is not possible to implement an abstract class that has a method with default access in another package. It just doesn't compile. This shows that the method has default access (closed package), and is not protected. This also indicates that 8.4.3.1 does not actually require that you can always implement an abstract method, simply by eliminating meaningless options such as private abstract void method()
For example, compilation:
package example; public abstract class AbstractTest { abstract void testMethod(); }
and
package example.sub;
import example.AbstractTest; public class TestImpl extends AbstractTest { void testMethod() {
Causes a compilation error:
example\sub\TestImpl.java:8: error: TestImpl is not abstract and does not override abstract method testMethod() in AbstractTest public class TestImpl extends AbstractTest { ^ 1 error
source share