Bird
Raised Fist0

Given these classes, what will print(c.describe()) output?

hard🚀 Application Q15 of Q15
Python - Inheritance and Code Reuse
Given these classes, what will print(c.describe()) output?
class Parent:
    def describe(self):
        return "I am a parent"

class Child(Parent):
    def describe(self):
        parent_desc = super().describe()
        return parent_desc + " and I am a child"

c = Child()
AI am a parent
BI am a parent and I am a child
CI am a child
DError: super() used incorrectly
Step-by-Step Solution
Solution:
  1. Step 1: Understand super() usage in child describe method

    The child method calls super().describe() which runs the parent method returning "I am a parent".
  2. Step 2: Combine parent and child strings

    The child method adds " and I am a child" to the parent's string, so the full return is "I am a parent and I am a child".
  3. Final Answer:

    I am a parent and I am a child -> Option B
  4. Quick Check:

    super() calls parent method, combined output [OK]
Quick Trick: Use super() to add parent behavior inside child method [OK]
Common Mistakes:
MISTAKES
  • Expecting only child or only parent output
  • Thinking super() causes error without arguments
  • Ignoring string concatenation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes