What will be the result of the following code execution?

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

    A() {}

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

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

    B() {}

class Test {
    public static void main(String... args) {
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
Keep exploring
Java quizzes
Sign Up Now
or Subscribe for future quizzes