NAMES
Determining Accessibility
6.6.1
6.6 Qualified Names and Access Control
Qualified names are a means of access to members of packages and reference
types; related means of access include field access expressions ( 15.10) and
method invocation expressions ( 15.11). All three are syntactically similar in that
a
.
token appears, preceded by some indication of a package, type, or expres
sion having a type and followed by an
Identifier
that names a member of the pack
age or type. These are collectively known as constructs for
qualified access
.
Java provides mechanisms for
access control
, to prevent the users of a pack
age or class from depending on unnecessary details of the implementation of that
package or class. Access control applies to qualified access and to the invocation
of constructors by class instance creation expressions ( 15.8), explicit constructor
invocations ( 8.6.5), and the method
newInstance
of class
Class
( 20.3.6).
If access is permitted, then the accessed entity is said to be
accessible
.
6.6.1 Determining Accessibility
Whether a package is accessible is determined by the host system ( 7.2).
If a class or interface type is declared
public
, then it may be accessed by any
Java code that can access the package in which it is declared. If a class or
interface type is not declared
public
, then it may be accessed only from
within the package in which it is declared.
A member (field or method) of a reference (class, interface, or array) type or a
constructor of a class type is accessible only if the type is accessible and the
member or constructor is declared to permit access:
N
If the member or constructor is declared
public
, then access is permitted.
All members of interfaces are implicitly
public
.
N
Otherwise, if the member or constructor is declared
protected
, then access
is permitted only when one of the following is true:
Access to the member or constructor occurs from within the package
containing the class in which the
protected
member is declared.
Access occurs within a subclass of the class in which the
protected
member is declared, and the access is correct as described in 6.6.2.
N
Otherwise, if the member or constructor is declared
private
, then access is
permitted only when it occurs from within the class in which it is declared.
N
Otherwise, we say there is default access, which is permitted only when the
access occurs from within the package in which the type is declared.
99
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