Java Quick Reference
  Language Fundamentals
  Operators and Assignments
  Flow Control and Exceptions
  Declarations and Access Control
  Garbage Collection
  Overloading and Overriding
  Threads
  The java.lang Package
  The java.util Package
  The java.awt Package
  The java.io Package
  References
  Miscellaneous Notes
  Tips & Traps
  Mock Exams

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

Encapsulation Polymorphism isA/hasA Overloading Overriding Field Variables
Initialization Top-level Classes Inner Classes Static Nested Classes Local Classes Anonymous Classes