What will be the output of the program? interface Foo141
{
int k = 0; /* Line 3 */
}
public class Test141 implements Foo141
{
public static void main(String args[])
{
int i;
Test141 test141 = new Test141();
i = test141.k; /* Line 11 */
i = Test141.k;
i = Foo141.k;
}
}
Correct Answer: Compiles and runs ok.
Explanation:
The variable k on line 3 is an interface constant, it is implicitly public, static, and final. Static variables can be referenced in two ways:
Via a reference to any instance of the class (line 11)