Skip to main content
Python Output Prediction Hard +35 XP

Class Inheritance MRO

What does this print?

PythonRead-only
class A: def greet(self): return "A"
class B(A): pass
class C(A): def greet(self): return "C"
class D(B, C): pass
print(D().greet())

What is the output?

Show answer and explanation

Answer: C

Python MRO (C3 linearization): D -> B -> C -> A. B has no greet(), so C's greet() is found first.

Hint: Python follows MRO left to right, depth first.

What this challenge tests

Output Prediction in Python: oop, mro, inheritance.

Related challenges