| preferred AP College board partner for AP classes
AP Computer Science A/Unit 9: Inheritance
Start Practice TestPractice Test
About Exam
hard
Constructor and Initializer Block Execution Order
< Prev
Next >

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

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy