Question 10
Back to Exercise
What is the output of the following Python program?
class Parent:
x = 1
class Child1(Parent):
pass
class Child2(Parent):
x = 2
Parent.x = 10
print(Parent.x, Child1.x, Child2.x)
- A 10 1 2
- B 1 1 2
- C 10 10 10
- D 10 10 2 Correct
Correct Answer: Option D
Child1 has no x of its own and finds Parent.x (now 10); Child2 overrides it.
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!