For the following code sample:
interface foo {
int k = 0;
}
public class
test implements foo {
public static void main(
String args[]) {
int i;
test t = new test();
i= t.k;
i= test.k;
i= foo.k;
}
}
What is the result?
A. Compilation succeeds.
B. An error at line 2 causes compilation to fail.
C. An error at line 9 causes compilation to fail.
D. An error at line 10 causes compilation to fail.
E. An error at line 11 causes compilation to fail.
Ans: A
Doubt: if I modify the code as
int i;
System.out.println(i);
test t = new test();
System.out.println(i);
i= t.k;
it gives compilation error �variable i might not have been initialized�.
Why is this so?
pls help
regards,
gitesh