Java Reference
In-Depth Information
The scope of a local class declaration immediately enclosed by a switch block statement
group (§ 14.11 ) is the rest of the immediately enclosing switch block statement group, in-
cluding its own class declaration.
The scope of a local variable declaration in a block (§ 14.4 ) is the rest of the block in which
the declaration appears, starting with its own initializer and including any further declarat-
ors to the right in the local variable declaration statement.
The scope of a local variable declared in the ForInit part of a basic for statement (§ 14.14.1 )
includes all of the following:
• Its own initializer
• Any further declarators to the right in the ForInit part of the for statement
• The Expression and ForUpdate parts of the for statement
• The contained Statement
The scope of a local variable declared in the FormalParameter part of an enhanced for
statement (§ 14.14.2 ) is the contained Statement .
The scope of a parameter of an exception handler that is declared in a catch clause of a try
statement (§ 14.20 ) is the entire block associated with the catch .
The scope of a variable declared in the ResourceSpecification of a try -with-resources state-
ment (§ 14.20.3 ) is from the declaration rightward over the remainder of the ResourceSpe-
cification and the entire try block associated with the try -with-resources statement.
The translation of a try -with-resources statement implies the rule above.
Example 6.3-1. Scope and Type Declarations
These rules imply that declarations of class and interface types need not appear before
uses of the types. In the following program, the use of PointList in class Point is valid,
because the scope of the class declaration PointList includes both class Point and class
PointList , as well as any other type declarations in other compilation units of package
points .
package points;
class Point {
int x, y;
PointList list;
Point next;
}
class PointList {
Search WWH ::




Custom Search