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 ).
Every declaration that introduces a name has a scope 6.3 ) , which is the part of the program
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.
In determining the meaning of a name (§ 6.5 ) , the context of the occurrence is used to dis-
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
by a qualified name, a field access expression (§ 15.11 ) , or a method invocation expression
15.12 ) in which the method is not specified by a simple name. The default access is that
a member can be accessed anywhere within the package that contains its declaration; other
possibilities are public , protected , and private .
Fully qualified and canonical names (§ 6.7 ) are also discussed in this chapter.
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:
• A package, declared in a package declaration (§ 7.4 )
Search WWH ::




Custom Search