Bird
0
0

Identify the problem in this code:

medium📝 Debug Q7 of 15
Python - Inheritance and Code Reuse
Identify the problem in this code:
class Base:
    def info(self):
        print('Base info')

class Derived(Base):
    def info(self):
        Base.info()
        print('Derived info')

d = Derived()
d.info()
ANo problem, code runs fine
BBase.info() should be called with self: self.Base.info()
CBase class info method is missing self parameter
DBase.info() should be called with instance: Base.info(d)
Step-by-Step Solution
Solution:
  1. Step 1: Check how Base.info() is called

    Calling Base.info() without an instance causes error because method needs self.

  2. Step 2: Correct call requires passing instance

    It should be Base.info(self) or Base.info(d) to pass the instance.

  3. Final Answer:

    Base.info() should be called with instance: Base.info(d) -> Option D
  4. Quick Check:

    Parent method call needs instance = A [OK]
Quick Trick: Call parent method with instance or use super() [OK]
Common Mistakes:
  • Calling parent method without instance
  • Confusing self with class name
  • Ignoring super() usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes