ProgrammingVery hardGATE CS · Product-company placement
Which statement about the C3 method resolution order is correct for `class D(B, C)` where both B and C inherit from A?
- A. D's MRO is D, B, C, A, object, and super() inside B.method can call C.method when the instance is a D
- B. D's MRO is D, B, A, C, object (depth-first), so super() in B always reaches A
- C. super() in B always calls A's method, whatever the actual type of self
- D. Python raises TypeError because both bases share the parent A
Correct answer: A. D's MRO is D, B, C, A, object, and super() inside B.method can call C.method when the instance is a D
C3 linearisation keeps each class before its parents and respects base order, giving D, B, C, A, object. super() follows the MRO of type(self), so in a D instance B's super() is C, which is what makes cooperative multiple inheritance work.
More Python Programming questions
- Which is the safest way to remove every even number from a list nums in place (so that other references to the same list see the change)?
- What is printed? python import sys a = [] b = a c = [a, a] print(sys.getrefcount(a) - sys.getrefcount([]) >= 3, c[0] is c[1], [a] == [b])
- What is printed? python x = (1, 2, 3) y = x + (4,) z = x 0 print(len(y), z, x.count(2), x.index(3), 3 in x)
- What is printed? python s = "a1b22c333" digits = "".join(ch for ch in s if ch.isdigit()) letters = [ch for ch in s if ch.isalpha()]…
- What is printed? python def f(n, memo={}): if n in memo: return memo[n] r = n if n < 2 else f(n - 1) + f(n - 2) memo[n] = r return r f(10)…
- What is printed? python def f(): x = 1 def g(): return x x = 2 return g def h(): for x in [1, 2]: pass return lambda: x print(f()(), h()())