What will be the output of the following Python program?

class A:
    pass

class B(A):
    pass

class C(A):
    pass

class D(B, C):
    pass

print([x.__name__ for x in D.mro()])
                        

Options

  • A. [D, C, B, A, object]
  • B. [D, B, C, A, object]
  • C. [A, B, C, D, object]
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

B. [D, B, C, A, object]

Detailed Explanation

Python uses C3 linearization for Method Resolution Order (MRO). The order is D, B, C, A, object.