Inner Classes : Inner Classes « Object Oriented « SCJP






An inner class is declared inside (between the opening and closing curly braces). 

class MyClass{
    class MyInnerClass{
    }
}


A normal Java class can have another class declared inside it: a member of the normal class. 

Member classes cannot have the same name as the enclosing class. 

If the class is declared static, it is called a nested class and can access only static methods and variables. 

Inner classes can be named or anonymous. 

For a local inner class (inside a method) to use local variables or method parameters, 
it must be declared final.








6.8.Inner Classes
6.8.1.Inner Classes
6.8.2.You can declare nested classes in any block, including blocks that are part of a method
6.8.3.A member inner class
6.8.4.Instances of the inner class retain the ability to access the members of the outer class.
6.8.5.The Enclosing this Reference and Construction of Inner Classes
6.8.6.Create an instance of an inner class from a static method.
6.8.7.Member Classes Access Modifiers
6.8.8.Static Inner Classes
6.8.9.Methods of a static inner class cannot use the keyword this (either implied or explicit)
6.8.10.Create an instance of a static inner class without the need for a current instance of the enclosing class
6.8.11.Classes Defined inside Methods
6.8.12.Classes declared in methods cannot be marked as static.
6.8.13.An object created from an inner class within a method can have access to the final variables of the enclosing method.
6.8.14.Use new C().m1() to invoke the m1() method of a newly created C object.
6.8.15.An instance of an inner class cannot be created without first creating an instance of its outer class.
6.8.16.Create an instance of Outer and pass it as the enclosing object instance for a new Inner object
6.8.17.Create an instance of Inner when this refers to the instance of the enclosing object.
6.8.18.Construct the Outer and Inner objects within the same statement.
6.8.19.Refer to the instance of the outer class from within the inner class.
6.8.20.Static inner classes are not instantiated as separate object instances.
6.8.21.Local Inner Classes
6.8.22.Instantiate and use a method-local inner class
6.8.23.Attempts to access a local variable from within a method-local inner class.
6.8.24.Referencing the Inner or Outer Instance from Within the Inner Class
6.8.25.A regular inner class is scoped inside another class's curly braces, but outside any method code
6.8.26.Nested static class
6.8.27.Nested interface
6.8.28.Inner class anonymous
6.8.29.A Member Inner Class Example
6.8.30.A Local Inner Class Example
6.8.31.Access to Local Variables
6.8.32.Using a Member Inner Class Object
6.8.33.Instance of NestedClass refers to the associated instance of NormClass