A protected
member or constructor of an object may be accessed from outside
the package in which it is declared only by code that is responsible for the implementation of that object. Let C be the class in which a protected
member or constructor is declared and let S be the subclass of C in whose declaration the use of
the protected
member or constructor occurs. Then:
protected
member (field or method), let Id be its name. Consider then the means of qualified access:
super.
Id, then the access is permitted.
.
Id, where Q is a TypeName, then the access is permitted if and only if Q is S or a subclass of S.
.
Id, where Q is an ExpressionName, then the access is permitted if and only if the type of the expression Q is S or a subclass of S.
.
Id, where E is a Primary expression, or by a method invocation expression E.
Id(
. . .)
, where E is a Primary expression, then the access is permitted if and only if the type of E is S or a subclass of S.
protected
constructor:
super(
. . .)
, then the access is permitted.
new
T(
. . .)
, then the access is not permitted. (A protected
constructor can be accessed by a class instance creation expression only from within the package in which it is defined.)
newInstance
of class Class
(§20.3.6), then the access is not permitted.