Are you taking CLEP classes? Try clep.ai
| 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

Mark
< Prev
Next >

Consider the following class declarations.

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();
    }
}

What output is produced when the main method in the Test class is executed?

A

B block
A block
B constructor
A constructor

B

A block
B block
A constructor
B constructor

C

B block
B constructor
A block
A constructor

D

A block
A constructor
B block
B 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.

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|