Bird
0
0

Which of the following is the correct syntax to override a method display in a child class?

easy📝 Syntax Q3 of 15
Python - Inheritance and Code Reuse

Which of the following is the correct syntax to override a method display in a child class?

Adef display(self, arg):<br> print('Child display')
Bdef display():<br> print('Child display')
Cdef display(self):<br> print('Child display')
Ddef display(self):<br> return 'Child display'
Step-by-Step Solution
Solution:
  1. Step 1: Check method signature for overriding

    The method must have the same name and parameters; here, self is required as the first parameter.
  2. Step 2: Confirm method body is valid

    Printing inside the method is valid; returning a string is also valid but changes behavior.
  3. Final Answer:

    def display(self): print('Child display') -> Option C
  4. Quick Check:

    Override method = same name + self parameter [OK]
Quick Trick: Override method with same name and self parameter [OK]
Common Mistakes:
  • Omitting self parameter
  • Changing method parameters
  • Returning instead of printing when original prints

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes