Java Reference
In-Depth Information
The scope of a local class declaration immediately enclosed by a switch block statement
cluding its own class declaration.
the declaration appears, starting with its own initializer and including any further declarat-
ors to the right in the local variable declaration statement.
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
The scope of a parameter of an exception handler that is declared in a
catch
clause of a
try
The scope of a variable declared in the
ResourceSpecification
of a
try
-with-resources state-
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 {