Please enable JavaScript.
Coggle requires JavaScript to display documents.
Inner Class (Types (Anonymous inner class (new InterfaceName(args){......}…
Inner Class
Types
Static inner class
-
doesn't need to create outer class instance, can be used independently.
Instance inner class
-
must create outer instance first
Outer outer = new Outer();
Outer.Inner in = outer.new Inner();
in.innerMethod();
-
method inner class
-
if in static method, only access to static outer members
otherwise also access to instance members
accessible to final local var and method arguments, by passing arguments to constructor of the inner class
Anonymous inner class
-
-
no constructor, using static block instead
-
-
-
compiler will compile inner classes as independent classes,
JVM doesn't know inner class