Question 4
Back to Exercise
What is the output of the following Python program?
class A:
def __init__(self):
print("A", end=" ")
class B(A):
def __init__(self):
print("B", end=" ")
super().__init__()
class C(A):
def __init__(self):
print("C", end=" ")
super().__init__()
class D(B, C):
def __init__(self):
print("D", end=" ")
super().__init__()
D()
print()
- A D B A C A
- B D B A
- C D B C A Correct
- D D C B A
Correct Answer: Option C
super() in B continues with the next class in D's MRO, which is C – not A. So every __init__ runs once.
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!