Local class can access only final variables defined inside the method (including method arguments). This is because the class can outlive the method, but the method local variables will go out of scope - in case of final variables, compiler makes a copy of those variables to be used by the class.
I try to use the local class object after its enclosing method dies in the following code, but without success. Can someone give me an example to show how local class outlive its enclosing method?
Sun Certified Java Programmer
posted 15 years ago
I have made some changes to the original code [B] [/B]] check u r code how can u refer the variable 'in' in another method after itz scope is over. now for u r original qiestion. u can return the object of the inner class from a method and that object can be accessed after the method is over. please check the code above please dont try to access the variable directly instead to make the concept clear use a method inside the inner class and access it from outside for that u have to first define an interface which defines that method. I want to add one more question to this discussion is there any use of an inner local class if i dont extend from some other class or implement an interface from some other context.Because i wont be able to refer to the local iner class in any other context.ofcourse i can use it inside the method but i dont find much use of doing that Cherry [This message has been edited by Cherry Mathew (edited January 16, 2001).] [This message has been edited by Cherry Mathew (edited January 16, 2001).]