📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!


    Question

    What happens if a subclass does not explicitly call a

    superclass constructor?
    A It results in a compilation error. Correct Answer Incorrect Answer
    B The superclass's default (no-argument) constructor is implicitly called. Correct Answer Incorrect Answer
    C The superclass is not initialized. Correct Answer Incorrect Answer
    D The subclass automatically creates a default constructor for the superclass. Correct Answer Incorrect Answer
    E The program crashes at runtime. Correct Answer Incorrect Answer

    Solution

    If a subclass constructor does not explicitly call a superclass constructor using super(), the compiler automatically inserts a call to the superclass's no-argument constructor as the first statement in the subclass constructor. If the superclass does not have a no-argument constructor, a compilation error will occur.

    Practice Next
    ask-question