🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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()]))
  1. A.... ... ...
  2. B.Woof Meow ...
  3. C.Woof Woof Woof
  4. 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 →