ProgrammingVery hardGATE CS · Product-company placement

What is printed?

What is printed?
class A:
    def __init__(self, **kw):
        print("A", sorted(kw), end=" ")
class B(A):
    def __init__(self, b=0, **kw):
        print("B", end=" ")
        super().__init__(**kw)
class C(A):
    def __init__(self, c=0, **kw):
        print("C", end=" ")
        super().__init__(**kw)
class D(B, C):
    pass
D(b=1, c=2, z=3)
  1. A. B A ['c', 'z']
  2. B. B C A ['z']
  3. C. B C A ['b', 'c', 'z']
  4. D. C B A ['z']

Correct answer: B. B C A ['z']

Cooperative multiple inheritance: D's MRO is D, B, C, A. Each __init__ consumes its own keyword and passes the rest along via super(), so A finally receives only z.

More Python Programming questions

Exams that ask this topic