Multiple choice technology programming languages

5 What will be printed when you execute the code? class A { A() { System.out.println("Class A Constructor"); } } public class B extends A { B() { System.out.println("Class B Constructor"); } public static void main(String args[]) { B b = new B(); } }

    1. Class A Constructor followed by Class B Constructor
    1. Class B Constructor followed by Class A Constructor
    1. Compile time error
    1. Run time error
Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

In Java, when a subclass object is created, the superclass constructor is called first (implicitly or explicitly). Therefore, A's constructor runs first, followed by B's constructor.