from appliedreasoning # 60
Which of the following code fragments will not cause a compile/runtime error at the <code here> section?
public class InnerTest
{
private
String s = "outer";
private static int time = 1;
public static void main(String[] args)
{
new InnerTest().run(args);
}
public void run(String[] args)
{
int num = 4;
final int finalNum = 2;
class Inside
{
public void execute()
{
<code here>
}
}
new Inside().execute();
}
}
A. System.out.println(s);
B. System.out.println(args);
C. System.out.println(num);
D. System.out.println(time);
E. System.out.println(finalNum);
I picked E because I very have very specifically spelled out in my notes that a Local Nested Inner Class can access any final local variables in their scope. The solution claims that A, D, E are correct but I fail to see how s or time are final local variables in the scope of this Local Inner Class. I compiled the various solutions they suggest and indeed A, D & E all work fine. Am I missing something or do I have a misconception as to what final local variables are?. Please help.
Thanks in advance for the input ... Gerry