Bird
Raised Fist0

Which approach correctly achieves this?

hard🚀 Application Q8 of Q15
Python - Polymorphism and Dynamic Behavior
You have a parent class with a method that returns a string. You want the child class to override this method but also add extra text after calling the parent method. Which approach correctly achieves this?
AOverride method without calling parent method and return only extra text.
BCall parent method directly without self and add extra text.
CUse super() to call parent method, then add extra text and return combined string.
DDefine a new method in child class with a different name.
Step-by-Step Solution
Solution:
  1. Step 1: Understand method overriding with extension

    To add extra behavior, call the parent method using super() to get its result.
  2. Step 2: Combine parent result with extra text

    Concatenate or format the returned string with extra text and return the combined result.
  3. Final Answer:

    Use super() to call parent method, then add extra text and return combined string. -> Option C
  4. Quick Check:

    Extend parent method by calling super() and adding extra [OK]
Quick Trick: Call super(), then add extra behavior in child method [OK]
Common Mistakes:
MISTAKES
  • Calling parent method without self
  • Not calling parent method at all
  • Changing method name instead of overriding

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes