posted 19 years ago
Hi,
Following is a question from JohnJunt Mock Exam.
Which variables can an inner class access from the class which encapsulates it?
A. All static variables
B. All final variables
C. All instance variables
D. Only final instance variables
E. Only final static variables
Select all correct answers
The answers are A, B,C. But i think this is wrong because:
1. methods of a static inner class cannot access instance variables or methods of the enclosing class. This is because static inner class doesnot have a reference to the enclosing class object.
2. methods of static local class cannot access instance variables of the enclosing class. same reason as above
3. if the anonymous inner class is static(implicitly), it cannot access any instance variables of the enclosing class
When exam says inner class, which inner class do they mean?. Is that all inner classes or a specific type of inner class?
Thanks
biju