Bird
0
0

Find the error in this code:

medium📝 Debug Q6 of 15
Python - Multiple Inheritance and Method Resolution
Find the error in this code:
class A:
    def speak(self):
        return 'A speaks'

class B:
    def speak(self):
        return 'B speaks'

class C(A, B):
    def speak(self):
        return super(B, self).speak()

obj = C()
print(obj.speak())
AMissing parentheses in class definition
BNo error, code runs fine
Cspeak method missing in class C
DIncorrect use of super() with arguments
Step-by-Step Solution
Solution:
  1. Step 1: Understand super() usage

    super() usually called as super() or super(Class, self). Here, super(B, self) is incorrect in this context.
  2. Step 2: Why is it wrong?

    super(B, self) looks for method in parents of B, but self is instance of C, causing confusion.
  3. Final Answer:

    Incorrect use of super() with arguments -> Option D
  4. Quick Check:

    super() arguments must match class hierarchy [OK]
Quick Trick: Use super() without arguments or with current class [OK]
Common Mistakes:
  • Using wrong class in super() arguments
  • Forgetting to call super() properly
  • Assuming no error in super() usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes