| CHAPTER 6: Names |
Previous |
Java Language |
Index |
Next |
Names are used to refer to entities declared in a Java program. A declared entity (S6.1) is a package, class type, interface type, member (field or method) of a reference type, parameter (to a method, constructor, or exception handler), or local variable.
Names in Java programs are either simple, consisting of a single identifier, or qualified, consisting of a sequence of identifiers separated by ". " tokens (S6.2).
Every name introduced by a declaration has a scope (S6.3), which is the part of the Java program text within which the declared entity can be referred to by a simple name.
Packages and reference types (that is, class types, interface types, and array types) have members (S6.4). A member can be referred to using a qualified name N. x, 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 field or a method.
In determining the meaning of a name (S6.5), Java uses the context of the occurrence to disambiguate among packages, types, variables, and methods with the same name.
Access control (S6.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; access specifies the part of the Java program text within which the declared entity can be referred to by a qualified name, a field access expression (S15.10), or a method invocation expression (S15.11) 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 names (S6.7) and naming conventions (S6.8) are also discussed in this chapter.
The name of a field, parameter, or local variable may be used as an expression (S15.13.1). The name of a method may appear in an expression only as part of a method invocation expression (S15.11). The name of a class or interface type may appear in an expression only as part of a class instance creation expression (S15.8), an array creation expression (S15.9), a cast expression (S15.15), or an instanceof
expression (S15.19.2), or as part of a qualified name for a field or method. The name of a package may appear in an expression only as part of a qualified name for a class or interface type.
| © 1996 Sun Microsystems, Inc. All rights reserved. |