Java Reference
In-Depth Information
Chapter 6. Names
Names are used to refer to entities declared in a program.
A declared entity (§
6.1
) is a package, class type (normal or enum), interface type (normal or
annotation type), member (class, interface, field, or method) of a reference type, type para-
meter (of a class, interface, method or constructor), parameter (to a method, constructor, or
exception handler), or local variable.
Names in programs are either
simple
, consisting of a single identifier, or
qualified
, consisting
of a sequence of identifiers separated by “.” tokens (§
6.2
).
text within which the declared entity can be referred to by a simple name.
A qualified name
N.x
may be used to refer to a
member
of a package or reference type,
where
N
is a simple or qualified name and
x
is an identifier. If
N
names a package, then
x
is a member of that package, which is either a class or interface type or a subpackage. If
N
names a reference type or a variable of a reference type, then
x
names a member of that type,
which is either a class, an interface, a field, or a method.
ambiguate among packages, types, variables, and methods with the same name.
Access control (§
6.6
) can be specified in a class, interface, method, or field declaration to
control when
access
to a member is allowed. Access is a different concept from scope. Ac-
cess specifies the part of the program text within which the declared entity can be referred to
a member can be accessed anywhere within the package that contains its declaration; other
possibilities are
public
,
protected
, and
private
.
6.1. Declarations
A
declaration
introduces an entity into a program and includes an identifier (§
3.8
) that can
be used in a name to refer to this entity. A declared entity is one of the following: