Java Reference
In-Depth Information
BlockStatements BlockStatement
BlockStatement:
LocalVariableDeclarationStatement
ClassDeclaration
Statement
A block is executed by executing each of the local variable declaration statements and other
statements in order from first to last (left to right). If all of these block statements complete
normally, then the block completes normally. If any of these block statements complete ab-
ruptly for any reason, then the block completes abruptly for the same reason.
14.3. Local Class Declarations
A
local class
is a nested class (§8) that is not a member of any class and that has a name
All local classes are inner classes (§
8.1.3
).
Every local class declaration statement is immediately contained by a block (§
14.2
). Local
class declaration statements may be intermixed freely with other kinds of statements in the
block.
It is a compile-time error if a local class declaration contains any of the access modifiers
Example 14.3-1. Local Class Declarations
Here is an example that illustrates several aspects of the rules given above:
class Global {
class Cyclic {}
void foo() {
new Cyclic(); // create a Global.Cyclic
class Cyclic extends Cyclic {} // circular definition
{
class Local {}
{
class Local {} // compile-time error
}
class Local {} // compile-time error