Bird
Raised Fist0

Identify the problem in this code:

medium📝 Debug Q7 of Q15
Python - Polymorphism and Dynamic Behavior
Identify the problem in this code:
class Shape:
    def area(self):
        return 0

class Square(Shape):
    def area(self, side):
        return side * side

s = Square()
print(s.area())
ASquare class should not inherit from Shape.
BCalling area() without required 'side' argument causes error.
CShape.area should accept 'side' parameter.
DSquare.area should not override Shape.area.
Step-by-Step Solution
Solution:
  1. Step 1: Check method signatures

    Square.area requires 'side' argument, but s.area() is called without arguments.
  2. Step 2: Identify error cause

    Missing argument causes TypeError at runtime.
  3. Final Answer:

    Calling area() without required 'side' argument causes error. -> Option B
  4. Quick Check:

    Method arguments must match when calling [OK]
Quick Trick: Match method parameters when overriding [OK]
Common Mistakes:
MISTAKES
  • Calling method without required arguments
  • Changing method signature incorrectly
  • Assuming inheritance fixes argument mismatch

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes