Use of class definitions inside a method in Java
- by Bragaadeesh
Hi
public class TestClass
{
public static void main(String[] args)
{
TestClass t = new TestClass();
}
private static void testMethod(){
class TestMethodClass{
int a;
int b;
int c;
}
TestMethodClass testMethodClass = new TestMethodClass();
}
}
I found out that the above piece of code is perfectly legal in Java. I have the following questions.
What is the use of ever having a class definition inside a method?
Will a class file be generated for TestMethodClass
Its hard for me to imagine this concept in an Object Oriented manner. Having a class definition inside a behavior. Probably can someone tell me with equivalent real world examples.
Thanks