Bird
0
0

Identify the problem in this code:

medium📝 Debug Q7 of 15
Python - Class Methods and Static Methods
Identify the problem in this code:
class Calculator:
    @staticmethod
    def multiply(self, x, y):
        return x * y

print(Calculator.multiply(2, 3))
AMissing @classmethod decorator
BCannot call static method on class
CStatic method should not have 'self' parameter
Dmultiply method should be instance method
Step-by-Step Solution
Solution:
  1. Step 1: Check static method parameters

    Static methods do not receive self or cls automatically.
  2. Step 2: Identify parameter mismatch

    multiply incorrectly has self as first parameter, causing argument mismatch.
  3. Final Answer:

    Static method should not have 'self' parameter -> Option C
  4. Quick Check:

    Static methods don't take self parameter = B [OK]
Quick Trick: Remove self from static method parameters [OK]
Common Mistakes:
  • Including self in static method parameters
  • Confusing static and instance methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes