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.

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Продовжуйте вивчати
тести з Java
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести