← Quiz: Inheritance, ABC and MRO: all 10 questions
Quiz: Inheritance, ABC and MRO · Question 10 of 10
What does this print? (code)
What does this print?
class Animal:
def sound(self): return "..."
class Dog(Animal):
def sound(self): return "Woof"
class Cat(Animal):
def sound(self): return "Meow"
print(" ".join(a.sound() for a in [Dog(), Cat(), Animal()]))
- A.... ... ...
- B.Woof Meow ...
- C.Woof Woof Woof
- D.An error
Answer & explanation
Correct answer: Woof Meow ...
Polymorphism: each object uses its own class's version of sound().
Can you get the rest right without peeking?
Take the timed Quiz: Inheritance, ABC and MRO quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →