Bird
0
0

Identify the error in this code related to polymorphism:

medium📝 Debug Q6 of 15
Java - Polymorphism
Identify the error in this code related to polymorphism:
class Parent { void show() {} } class Child extends Parent { void show(int x) {} } public class Test { public static void main(String[] args) { Parent p = new Child(); p.show(); } }
ACannot assign Child object to Parent reference
BChild class does not override show() method
CParent class method show() is private
DMethod show() in Parent is static
Step-by-Step Solution
Solution:
  1. Step 1: Check method overriding rules

    Child class has show(int), which is method overloading, not overriding show() with no parameters.
  2. Step 2: Understand polymorphism call

    Parent reference calls show() with no arguments, but Child does not override that method, so Parent's show() runs.
  3. Final Answer:

    Child class does not override show() method -> Option B
  4. Quick Check:

    Overriding requires same method signature [OK]
Quick Trick: Overriding needs exact method signature match [OK]
Common Mistakes:
  • Confusing overloading with overriding
  • Thinking polymorphism works with overloaded methods
  • Assuming assignment causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes