Wednesday 20 February 2013

8. Considering the following code, Which variables may be referenced correctly at line 12?

8. Considering the following code, Which variables may be referenced correctly at line 12?


Choices:
a. a
b. b
c. c
d. d
e. e


Answer:-

A, B, C and E are correct.
Since Inner is not a static inner class, it has a reference to an enclosing object, and all the variables of that object are accessible. Therefore A and B are correct, even if b is private.
Variables in the enclosing method are only accessible when they are marked as final hence c is accessible but not d.
E is obviously correct as it is a parameter to the method containing line 12 itself.

No comments:

Post a Comment