Bird
0
0

Which of the following method declarations correctly overrides the method void display() in the superclass?

easy📝 Syntax Q3 of 15
Java - Inheritance

Which of the following method declarations correctly overrides the method void display() in the superclass?

Aprivate void display()
Bvoid display(int x)
Cpublic void display()
Dvoid Display()
Step-by-Step Solution
Solution:
  1. Step 1: Check method signature match

    Overriding requires same method name and parameters. Only public void display() matches void display() signature.
  2. Step 2: Check access modifier and case sensitivity

    public void display() uses public (allowed if superclass method is default or protected), private void display() is private (not allowed), void Display() has different case, void display(int x) changes parameters.
  3. Final Answer:

    public void display() -> Option C
  4. Quick Check:

    Exact signature and compatible access needed [OK]
Quick Trick: Same name and parameters, access can be same or less strict [OK]
Common Mistakes:
  • Changing method parameters (overloading, not overriding)
  • Changing method name case
  • Using private access in subclass

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes