What will be the result of the following code execution?

class A {
    static String a;
    {print("a");}
    static {a = print("A");}

    A() {}

    static String print(String s) {
        System.out.print(s + " ");
        return s;
    }
}

class B extends A {
    static String b;
    {print("b");}
    static {b = print("B");}

    B() {}
}

class Test {
    public static void main(String... args) {
        System.out.print(B.a);
    }
}
Explanation
In this case, the initialization is complete only for the class A, containing static variable a. Class B will not be initialized.

Follow CodeGalaxy

Mobile Beta

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