A class or interface C is accessible to a class or interface D if and only if one of the following is true:
- C is
public, and a member of the same run-time module as D (§5.3.6). - C is
public, and a member of a different run-time module than D, and C's run-time module is read by D's run-time module, and C's run-time module exports C's run-time package to D's run-time module. - C is not
public, and C and D are members of the same run-time package.
A field or method R is accessible to a class or interface D if and only if any of the following is true:
- R is
public. - R is
protectedand is declared in a class C, and D is either a subclass of C or C itself. Furthermore, if R is notstatic, then the symbolic reference to R must contain a symbolic reference to a class T, such that T is either a subclass of D, a superclass of D, or D itself. - R is either
protectedor has default access (that is, neitherpublicnorprotectednorprivate), and is declared by a class in the same run-time package as D. - R is
privateand is declared in D.
This discussion of access control omits a related restriction on the target of a protected field access or method invocation (the target must be of class D or a subtype of D). That requirement is checked as part of the verification process (§4.10.1.8); it is not part of link-time access control.