Bird
0
0

Which syntax correctly shows method overriding for runtime polymorphism in Java?

easy📝 Syntax Q12 of 15
Java - Polymorphism
Which syntax correctly shows method overriding for runtime polymorphism in Java?
Aclass Parent { void show() {} } class Child extends Parent { void show() {} }
Bclass Parent { void show() {} } class Child extends Parent { void display() {} }
Cclass Parent { void show() {} } class Child { void show() {} }
Dclass Parent { void show() {} } class Child extends Parent { void show(int x) {} }
Step-by-Step Solution
Solution:
  1. Step 1: Check method overriding rules

    Method overriding requires same method name and parameters in subclass extending superclass.
  2. Step 2: Match options with overriding

    class Parent { void show() {} } class Child extends Parent { void show() {} } shows subclass overriding show() method correctly; others differ in method name or parameters.
  3. Final Answer:

    class Parent { void show() {} } class Child extends Parent { void show() {} } -> Option A
  4. Quick Check:

    Same method name and parameters in subclass = overriding [OK]
Quick Trick: Overriding needs same method name and parameters in subclass [OK]
Common Mistakes:
  • Changing method name in subclass instead of overriding
  • Changing method parameters (overloading, not overriding)
  • Not extending the parent class

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes