|
A member inner class is defined inside the enclosing class’s body at the same level as the member variables are declared. Interestingly you can also declare an inner class inside a method body or a code block. Such inner class is called as the local inner class. The local classes that defined within a method body are specifically known as method-local inner classes.
|
|
Method-local inner classes and block inner classes behave exactly same. Method local classes are defined in method body whereas block local classes can be declared in any code block. |
Following code illustrates how you can define a method-local inner class MyLocalInner inside a method doSomething().
package com.example.scjp.studykit;
public class OuterOne {
void doSomething() {
class MyLocalInner {
}
}
The method-local class MyLocalInner is simply defined in the method doSomething(). It is not instantiated or used yet. Therefore, it is of no potential use yet. Let us see few declaration rules for method-local inner class before we look into its instantiation.