Skip to content
CodeKruPro

A classmethod called on a subclass

QuizMediumPython only

cls is the class that a classmethod was called on. What does the last line print?

class Tool:
    made = 0
    @staticmethod
    def helper(x):
        return x * 2
    @classmethod
    def create(cls):
        cls.made += 1
        return cls()

class Hammer(Tool):
    pass

h = Hammer.create()
print(type(h).__name__, Tool.helper(2), Hammer.made, Tool.made)
  • Hammer 4 1 0
  • Tool 4 1 1
  • Hammer 4 1 1
  • TypeError: helper() missing argument self

This question is part of Pro+

Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.

See Pro+

Already have Pro+? Sign in