ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
class A:
def __init__(self):
print("A", end=" ")
class B(A):
def __init__(self):
print("B", end=" ")
class C(B):
pass
C()
print(C.__init__ is B.__init__, C.__mro__[1].__name__)- A. A B True B
- B. B A True B
- C. B True B
- D. B False A
Correct answer: C. B True B
C inherits B.__init__, which does not call super(), so A.__init__ never runs. The attribute lookup returns the very same function object, and C's MRO is C, B, A, object.
More Python Programming questions
- What is printed? python class A: def f(self): return "A" class B(A): def f(self): return "B" + super().f() class C(A): def f(self): return…
- What is printed? python class A: x = 1 class B(A): pass class C(A): x = 3 class D(B, C): pass B.x = 2 del B.x print(D.x, D.mro.index(C))
- What is printed? python class Shape: sides = 0 def describe(self): return f"{type(self).name}:{self.sides}" class Tri(Shape): sides = 3…
- What is printed? python class Money: def init(self, v): self.v = v def lt(self, o): return self.v < o.v def repr(self): return…
- What is printed? python class A: def eq(self, o): print("A.eq", end=" ") return NotImplemented class B(A): def eq(self, o): print("B.eq"…
- What is printed? python class Lazy: def init(self): self.calls = 0 @property def value(self): self.calls += 1 return 42 from functools…