+ 3
Inner class object can't use the local variables of the method the inner class is in. Why ?
INNER CLASSES
5 Réponses
+ 13
Are the methods public? Are you using the inner class's object outside the inner class? Need any more hints?
+ 2
Thanks guys for the answers but I got the answer.
Actually we can't use local variables because as we know local variable resides on stack and vanishes as soon as method ends but on the other hand inner class object or any object resides on heap so it may be possible that the local variable no longer exists and someone tries to use the local variable via inner class object that is still alive on the heap.
So here is the explanation of my question.
+ 2
@Tashi N it really does not matter whether methods are public or private since inner classes are a member of the class so they can access private members too and we typically use object of inner class outside inner class because if we don't what will be use of defining the inner classes.
+ 2
@luka I don't have code to show. I have read it somewhere in the book and you can easily get one code by yourself. That does not gonna make any difference to the question. The question will remain WHY and just by seeing code one can't predict anything general about INNER CLASSES