6.6.2
Details on
protected
Access
NAMES
6.6.2 Details on
protected
Access
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 imple
mentation of that object. Let
C
be the class in which a
protected
member or con
structor is declared and let
S
be the subclass of
C
in whose declaration the use of
the
protected
member or constructor occurs. Then:
If an access is of a
protected
member (field or method), let
Id
be its name.
Consider then the means of qualified access:
N
If the access is by a field access expression of the form
super.Id
, then the
access is permitted.
N
If the access is by a qualified name
Q.Id
, where
Q
is a
TypeName
, then the
access is permitted if and only if
Q
is
S
or a subclass of
S
.
N
If the access is by a qualified name
Q.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
.
N
If the access is by a field access expression
E.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
.
Otherwise, if an access is of a
protected
constructor:
N
If the access is by a superclass constructor invocation
super(
. . .
)
, then the
access is permitted.
N
If the access is by a class instance creation expression
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.)
N
If the access is by an invocation of the method
newInstance
of class
Class
( 20.3.6), then the access is not permitted.
6.6.3 An Example of Access Control
For examples of access control, consider the two compilation units:
package points;
class PointVec { Point[] vec; }
100
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved