This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
The class Person is inside Lab1 class.In Lab1 a static variable pers of type Person is declared and used inside the main().Even though pers is of static type why is not possible to compile Lab1.If Person class is made static Lab1 compiles and returns the expected output.Since pers is inside main() it is of type static and it will refer to what ever exact object it will be pointed to.
Yes. The class you created inside the main() is a method local inner class. There is a special case with the method local inner classes.I recommend you to go through the static inner class, method local inner class and the anonymous inner and argument-defined anonymous inner class in deep. They are very important concepts of Java and are very helpful in certain cases.
Hope this helps.
Joined: Jan 15, 2007
Originally posted by Sudipto Shekhar:
I changed the way the of the object creation of the method-local inner class and it works fine. I hope this explains what you are looking for.
[ December 11, 2008: Message edited by: Varuna Seneviratna ]