Hello and welcome back to Java Code Online. Today I will be discussing about the Method Local Inner Class in Java. It is one of the four subtypes of Inner Classes.
The Method Local Inner class, as the name specifies is local to a method. It implies that the method local Inner class is defined inside a method of a class. As the class is defined inside a method, it needs to be instantiated from with in the same method, but after the class definition is finished. As a mater of fact this inner class cannot use the variables of the same method, unless they are declared final.
If you did not instantiate the class within the same method and after the class definition is finished, then that inner class though valid will be useless, as there is no other way to instantiate it. Moreover the Instantiation must be after the class definition or else the Java Compiler will not be able to see it.
Hoping that this article was helpful to you all. Do post a comment if you liked this article.
Types of Inner Class
1. Regular Inner Class
2. Method Local Inner Class
3. Anonymous Inner Class
4. Static Nested Inner Class
Keep buzzing Java Code Online for more Java Information.