🎙 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 5 of 10

What does this print? (code)

What does this print?

class A: pass
class B(A): pass
class C(A): pass
class D(B, C): pass
print([k.__name__ for k in D.__mro__])
  1. A.['D', 'B', 'A', 'C', 'object']
  2. B.['D', 'C', 'B', 'A', 'object']
  3. C.['D', 'B', 'C', 'object', 'A']
  4. D.['D', 'B', 'C', 'A', 'object']
Answer & explanation

Correct answer: ['D', 'B', 'C', 'A', 'object']

The common parent A comes only after both B and C.

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 →