Bird
0
0

Find the problem in this code snippet:

medium📝 Debug Q7 of 15
Java - Polymorphism
Find the problem in this code snippet:
class Parent { final void display() { System.out.println("Parent"); } } class Child extends Parent { void display() { System.out.println("Child"); } }
ANo problem, code compiles fine
BCannot override final method
CMethod signature mismatch
DMissing @Override annotation
Step-by-Step Solution
Solution:
  1. Step 1: Identify final method in Parent class

    display() is declared final, so it cannot be overridden.
  2. Step 2: Check Child class method

    Child tries to override display(), which causes a compile-time error.
  3. Final Answer:

    Cannot override final method -> Option B
  4. Quick Check:

    Final methods cannot be overridden [OK]
Quick Trick: Final methods cannot be overridden in subclasses [OK]
Common Mistakes:
  • Ignoring final keyword effect
  • Assuming @Override annotation is mandatory
  • Thinking method signature mismatch causes error here

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes