ProgrammingVery hardGATE CS · Product-company placement

What is printed?

What is printed?
class Meta(type):
    def __new__(m, name, bases, ns):
        ns["kind"] = name.upper()
        return super().__new__(m, name, bases, ns)
class A(metaclass=Meta): pass
class B(A): pass
print(A.kind, B.kind, type(B).__name__, isinstance(A, type))
  1. A. A A Meta True
  2. B. A B type True
  3. C. A B Meta True
  4. D. A A type False

Correct answer: C. A B Meta True

A metaclass is inherited by subclasses, so creating B also runs Meta.__new__ and sets B.kind = 'B'. Classes are instances of their metaclass, which is itself a subclass of type.

More Python Programming questions

Exams that ask this topic