ProgrammingVery hardGATE CS · Product-company placement

What is printed? (Output lines are shown separated by " / ".)

What is printed? (Output lines are shown separated by " / ".)
class A:
    @staticmethod
    def s(): return "s"
    @classmethod
    def c(cls): return cls.__name__
    def i(self): return type(self).__name__
class B(A): pass
print(B.c(), B().c(), B().i(), A.s() + B().s())
try:
    A.i()
except TypeError:
    print("TE")
  1. A. B B B ss / TE
  2. B. A A B ss / TE
  3. C. B B A ss / TE
  4. D. B B B ss / A

Correct answer: A. B B B ss / TE

A classmethod receives the class it is called on (B, whether through the class or an instance). Calling the plain method A.i() without an instance is missing self and raises TypeError.

More Python Programming questions

Exams that ask this topic