Question 3
Back to Exercise
What is the output of the following Python program?
class A:
def hi(self): return "A"
class B(A):
def hi(self): return "B"
class C(A):
def hi(self): return "C"
class D(B, C):
pass
print(D().hi(), [k.__name__ for k in D.__mro__])
- A C ['D', 'C', 'B', 'A', 'object']
- B B ['D', 'B', 'C', 'A', 'object'] Correct
- C A ['D', 'B', 'A', 'C', 'object']
- D B ['D', 'B', 'A', 'C', 'object']
Correct Answer: Option B
D has no hi of its own; the first class in the MRO that defines it is B.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!