Bird
0
0

Find the error in this code:

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

class Child(Parent):
    def greet(self):
        print("Hi")

obj = Child()
obj.greet
AChild class must call super().greet() explicitly.
BChild class should not override greet method.
CParent class greet method is private.
DMissing parentheses when calling greet method.
Step-by-Step Solution
Solution:
  1. Step 1: Check method call syntax

    Method calls require parentheses; here, obj.greet misses them.
  2. Step 2: Identify error cause

    Without parentheses, greet is a method object, not called, so no output.
  3. Final Answer:

    Missing parentheses when calling greet method. -> Option D
  4. Quick Check:

    Method call needs () [OK]
Quick Trick: Always use () to call methods [OK]
Common Mistakes:
  • Forgetting () on method calls
  • Thinking override is error
  • Assuming super() call is mandatory

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes