Bird
0
0

If a subclass defines a method with the same name as one in its superclass, what is the effect when calling that method on a subclass instance?

easy📝 Conceptual Q1 of 15
Python - Polymorphism and Dynamic Behavior
If a subclass defines a method with the same name as one in its superclass, what is the effect when calling that method on a subclass instance?
ABoth methods are called automatically in sequence
BThe superclass method is always called, ignoring the subclass method
CThe subclass method is called, overriding the superclass method
DAn error occurs due to method name conflict
Step-by-Step Solution
Solution:
  1. Step 1: Understand method overriding

    When a subclass defines a method with the same name as its superclass, it replaces the superclass method for instances of the subclass.
  2. Step 2: Method call on subclass instance

    Calling the method on a subclass instance invokes the subclass's version, not the superclass's.
  3. Final Answer:

    The subclass method is called, overriding the superclass method -> Option C
  4. Quick Check:

    Subclass method overrides superclass method [OK]
Quick Trick: Subclass method overrides parent method [OK]
Common Mistakes:
  • Thinking superclass method is called instead
  • Assuming both methods run automatically
  • Believing an error occurs due to name clash

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes