LearnFrenzy
Sign in Take a free test

Inheritance and Polymorphism · Predict the Output · Question 13

super() through three levels Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 13 Back to Exercise

What is the output of the following Python program?

main.py
class A:
    def total(self): return 1
class B(A):
    def total(self): return super().total() + 10
class C(B):
    def total(self): return super().total() + 100

print(C().total(), B().total(), [k.__name__ for k in C.__mro__][:3])
  • A 111 11 ['C', 'B', 'A'] Correct
  • B 100 10 ['C', 'B', 'A']
  • C 111 11 ['A', 'B', 'C']
  • D 101 11 ['C', 'B', 'A']
Correct Answer: Option A

Each level adds to the result of the level above: 1 + 10 + 100.

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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links