Bird
Raised Fist0

Find the error in this code:

medium📝 Debug Q6 of Q15
Python - Inheritance and Code Reuse
Find the error in this code:
class Parent:
    def greet(self):
        print("Hello from Parent")

class Child(Parent):
    def greet(self):
        print("Hello from Child")

obj = Child()
obj.greet()
Parent.greet()
AParent.greet() missing self argument
BChild class missing inheritance
Cgreet method should return string, not print
DNo error
Step-by-Step Solution
Solution:
  1. Step 1: Check method calls

    Calling Parent.greet() without an instance misses the required self argument.
  2. Step 2: Understand method binding

    Instance methods require an object to be passed as self; calling directly on class causes error.
  3. Final Answer:

    Parent.greet() missing self argument -> Option A
  4. Quick Check:

    Instance methods need self argument [OK]
Quick Trick: Call instance methods on objects, not classes directly [OK]
Common Mistakes:
MISTAKES
  • Calling instance method on class without object
  • Confusing print vs return errors
  • Ignoring inheritance correctness

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes