LearnFrenzy
Sign in Take a free test

Inheritance and Polymorphism · Predict the Output · Question 1

Overriding and calling super() Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 1 Back to Exercise

What is the output of the following Python program?

main.py
class Animal:
    def speak(self):
        return "sound"

class Dog(Animal):
    def speak(self):
        return "Woof and " + super().speak()

print(Animal().speak(), "|", Dog().speak())
  • A sound | Woof
  • B sound | sound
  • C sound | Woof and sound Correct
  • D RecursionError
Correct Answer: Option C

super().speak() calls the parent version from inside the override.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links