What is the result of the following code compilation and execution?

public class Test extends A {
    public int i = 1;
    public static void main(String... args) {
        System.out.print(new Test().i);
        System.out.print(new A().i);
        System.out.print( ((A)new Test()).i );
    }
}

class A {
    public int i = 2;
}
Explanation
Fields cannot be overridden. Both fields exist in class Test, Test.i and A.i and they are accessed directly.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes