ProgrammingVery hardGATE CS · Product-company placement

What is printed?

What is printed?
class Meta(type):
    def __call__(cls, *a):
        print("meta", end=" ")
        return super().__call__(*a)
class K(metaclass=Meta):
    def __new__(cls, v):
        print("new", end=" ")
        return super().__new__(cls)
    def __init__(self, v):
        print("init", v, end=" ")
K(5)
  1. A. new init 5
  2. B. meta new init 5
  3. C. new meta init 5
  4. D. meta init 5

Correct answer: B. meta new init 5

Calling a class invokes its metaclass's __call__, which in turn calls __new__ to create the object and then __init__ to initialise it.

More Python Programming questions

Exams that ask this topic