Bird
0
0

Given the classes below, what will be the output when running new Child().display();?

hard📝 Application Q15 of 15
Java - Inheritance

Given the classes below, what will be the output when running new Child().display();?

class Parent {
    void display() {
        System.out.println("Parent display");
    }
}
class Child extends Parent {
    void display() {
        super.display();
        System.out.println("Child display");
    }
}
AChild display
BParent display Child display
CParent display
DCompilation error
Step-by-Step Solution
Solution:
  1. Step 1: Understand use of super in child method

    The child class's display() method calls super.display(), which runs the parent class's display() method first.
  2. Step 2: Determine output sequence

    First, "Parent display" is printed, then "Child display" is printed on the next line.
  3. Final Answer:

    Parent display Child display -> Option B
  4. Quick Check:

    super calls parent method before child output [OK]
Quick Trick: super.method() runs parent method inside child method [OK]
Common Mistakes:
  • Ignoring the call to super.display()
  • Expecting only child output
  • Thinking super causes error without constructor

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes