6.1 Declarations
A declaration introduces an entity into a Java 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)
- An imported type, declared in a single-type-import declaration (§7.5.1) or a type-import-on-demand declaration (§7.5.2)
- A class, declared in a class type declaration (§8.1)
- An interface, declared in an interface type declaration (§9.1)
- A member of a reference type (§8.2, §9.2, §10.7), one of the following:
- A field, one of the following:
- A field declared in a class type (§8.3)
- A constant field declared in an interface type (§9.3)
- The field
length
, which is implicitly a member of every array type (§10.7)
- A method, one of the following:
- A method (
abstract
or otherwise) declared in a class type (§8.4)
- A method (always
abstract
) declared in an interface type (§9.4)
- A parameter, one of the following:
- A parameter of a method or constructor of a class (§8.4.1, §8.6.1)
- A parameter of an
abstract
method of an interface (§9.4)
- A parameter of an exception handler declared in a
catch
clause of a try
statement (§14.18)
- A local variable, one of the following:
- A local variable declared in a block (§14.3)
- A local variable declared in a
for
statement (§14.12)
Constructors (§8.6) are also introduced by declarations, but use the name of the
class in which they are declared rather than introducing a new name.