Multiple choice technology testing

Local inner classes cannot access the local data members of the method in which they are defined.

  1. True

  2. False

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Local inner classes can access local variables from the enclosing method, but only if those variables are final or effectively final (not reassigned). This restriction ensures data consistency since the local variable might outlive the method's scope.

AI explanation

A local inner class is defined inside a method body and, in Java, it can freely access the local variables and parameters of that enclosing method (provided they are final or effectively final). This is a key feature that lets inner classes act as closures over their surrounding scope. So the statement that they cannot access those local members is false.