ProgrammingVery hardGATE CS · Product-company placement

What is printed?

What is printed?
class A:
    def f(self): return "A"
class B(A):
    def f(self): return "B" + super().f()
class C(A):
    def f(self): return "C" + super().f()
class D(B, C):
    pass
class E(C, B):
    def f(self): return "E" + super().f()
print(D().f(), E().f())
  1. A. BCA ECBA
  2. B. BA ECA
  3. C. BCA ECA
  4. D. BA ECBA

Correct answer: A. BCA ECBA

super() follows the MRO of the actual object: for D it is D, B, C, A, so B.f calls C.f, then A. For E it is E, C, B, A, so E.f -> C.f -> B.f -> A.f.

More Python Programming questions

Exams that ask this topic