Classes & Objects · Question 17 · Hard

Every class in this diamond calls super().go(). What string does D().go() build?

class A:
    def go(self): return "A"
class B(A):
    def go(self): return "B" + super().go()
class C(A):
    def go(self): return "C" + super().go()
class D(B, C):
    def go(self): return "D" + super().go()

print(D().go())
  1. DBA
  2. DBACA
  3. DCBA
  4. DBCA
Answer and explanation

Answer: D. DBCA

Explanation: super() follows the MRO of the object's class, which for D is D, B, C, A. So inside B, super() means C (not A), and each class is visited exactly once: D, B, C, A.

Previous: D inherits from both B and C, and B and C both inherit from A. Which who()… · Next: The Coin class defines both __str__ and __repr__. What is printed for the…

Practise classes & objects

Try a fresh set of classes & objects questions with an explanation after every answer, free and without signing up: Classes & Objects practice. Or sit a full placement mock test.

More classes & objects questions

More python practice

Exceptions & Files · Built-ins & Standard Library · Variables, Types & Operators · Python Strings · Lists & Tuples · Dictionaries & Sets · Conditions & Loops · Functions & Scope

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge