|
|
Overloading, Overriding, Runtime Types and Object Orientation - Local Classes
- may be declared within a block of code
class Outer {
void display() {
class Local {
// body of Local class
}
}
}
- the compiled name of the above Local class is: Outer$1$Local.class
- local inner classes are not class members and are not tied to an instance of the enclosing class
- as they are not class members, they cannot be instantiated outside of the code block in which they are declared by using the class as a reference ie new Outer.new Local(); won't work
- they may not be declared private, public, protected, or static. May be declared final
- they may access static and non-static members of the enclosing class
- they may only access final variables or parameters of the enclosing code block
Example Code
|