← 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__])
- A.['D', 'B', 'A', 'C', 'object']
- B.['D', 'C', 'B', 'A', 'object']
- C.['D', 'B', 'C', 'object', 'A']
- 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 →