🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Polymorphism: all 10 questions

Quiz: Polymorphism · Question 3 of 10

What does this print? (code)

What does this print?

class A:
    def show(self): return "A"
class B(A):
    def show(self): return "B"
items = [A(), B(), A()]
print("".join(x.show() for x in items))
  1. A.AAA
  2. B.ABA
  3. C.BBB
  4. D.AB
Answer & explanation

Correct answer: ABA

Each object runs its own show() method.

Can you get the rest right without peeking?

Take the timed Quiz: Polymorphism quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →