Constructor and Initializer Block Execution Order
What is the order of execution of the print statements when the above code is run?
public class A {
{ System.out.println("A block"); }
public A() { System.out.println("A constructor"); }
}
public class B extends A {
{ System.out.println("B block"); }
public B() { System.out.println("B constructor"); }
}
public class Test {
public static void main(String[] args) {
new B();
}
}
A
B block
A block
B constructor
A constructor
B
A block
A constructor
B block
B constructor
C
A block
B block
A constructor
B constructor
D
B block
B constructor
A block
A constructor
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE