|
Example Running the Example
| | A local class is a class defined within a block of Java code:
- in methods
- in static initializers
- in instance initializers
A local class is visible only within that Java block.
A local class is not a member class, but is still defined within an enclosing class.
A local class can access any final local variables or parameters that are accessible in
the scope of the block that defines the class.
Interfaces may not be defined locally.
Note:
- Because code can only appear inside a
class, local classes are nested within a containing
class, and so share many of the features of member
classes.
- Just like member classes, local
classes have a containing instance that is implicitly
passed to all constructors of the local class.
- Local classes can use the same this syntax as member classes, but not
the new or
super syntaxes.
- Local classes may not
contain static members.
- Local classes may not
be declared public,
protected, private, or
static
- Local classes may not
have the same name as any of its containing classes
|