aspose file tools*
The moose likes Beginning Java and the fly likes local variable accessed by a method of inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "local variable accessed by a method of inner class" Watch "local variable accessed by a method of inner class" New topic
Author

local variable accessed by a method of inner class

Thomas Markl
Ranch Hand

Joined: Mar 08, 2001
Posts: 192
56. „A local inner class can be accessed by the methods of an inner class only if it is _________
Anwer: „final“
A local variable is only visible inside the method. So now method outside the method can access the local variable. Therefore the inner class has to be inside that method where the local variable is defined. Therefore the inner class which can access a local variable must be a local or anonymous class because theses classes are inside methods. Local inner classes can only access local variables of the enclosing methods if they are final or parameter arguments.
Do you think my answer is correct?
Thomas
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
The original question seems to be nonsense. It's not talking about accessing a local variable, but rather a local class. Evidently this access would occur from another inner class. The only way I can imagine this working is if both inner classes are local or anonymous, defined inside the same method (or constructor or initializer), and if the class to be accessed is also final. This involves a lot of unstated assumptions that don't fit easily into the answer blank; I'd assume that either (a) the question is miscopied, or (b) the question author doesn't know what they're talking about. If it's the latter case, I wouldn't spend time worrying about what they meant.
Note that if we replace the original question with
"A local variable can be accessed by the methods of an inner class only if it is _________"
then your answer is correct.


"I'm not back." - Bill Harding, Twister
 
Consider Paul's rocket mass heater.
 
subject: local variable accessed by a method of inner class
 
Similar Threads
doubts from the john hunt's mock test
Anonymous Inner Class and final objects
Method local inner classes
final keyword for method parameters
FAQ Explanations