Bird
0
0

Identify the error in this code:

medium📝 Debug Q6 of 15
Python - Polymorphism and Dynamic Behavior
Identify the error in this code:
class Alpha:
    def display(self):
        print('Alpha display')

class Beta(Alpha):
    def display():
        print('Beta display')

obj = Beta()
obj.display()
AThe class Beta should not inherit from Alpha
BThe method <code>display</code> in Beta is missing the <code>self</code> parameter
CThe method <code>display</code> in Alpha should be static
DNo error, code runs fine
Step-by-Step Solution
Solution:
  1. Step 1: Check method signature

    In Python, instance methods must have self as the first parameter.
  2. Step 2: Identify missing self

    The display method in Beta lacks self, causing a TypeError when called on an instance.
  3. Final Answer:

    The method display in Beta is missing the self parameter -> Option B
  4. Quick Check:

    Instance methods require self parameter [OK]
Quick Trick: Instance methods must include self parameter [OK]
Common Mistakes:
  • Omitting self in subclass method
  • Thinking inheritance causes error
  • Assuming static method needed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes