About Question com.enthuware.ets.scjp.v6.2.203 :
Posted: Sun Apr 16, 2017 3:42 pm
I think the answer to this question is wrong
'Which variables of the encapsulating class can an inner class access, if the inner class is defined in an instance method of the encapsulating class?'
Of the suggested answers, 1,2,3 are clear enough.
[Option 5:All final automatic variables] would I think, only be admissible if there were ambiguity in the question, which there isn't.
Option 5 is untrue because:
(1) Automatic variables don't belong to the enclosing class, they can only appear in its methods.
(2) Even if we ignore (1), it's only automatic variables defined in the method containing the inner class that are visible, not automatic variables in any other method.
I'd be interested to hear your take on this.
'Which variables of the encapsulating class can an inner class access, if the inner class is defined in an instance method of the encapsulating class?'
Of the suggested answers, 1,2,3 are clear enough.
[Option 5:All final automatic variables] would I think, only be admissible if there were ambiguity in the question, which there isn't.
Option 5 is untrue because:
(1) Automatic variables don't belong to the enclosing class, they can only appear in its methods.
(2) Even if we ignore (1), it's only automatic variables defined in the method containing the inner class that are visible, not automatic variables in any other method.
I'd be interested to hear your take on this.