Python Method Overriding and Dynamic Dispatch
A Python class 'BankAccount' has a method 'withdraw(amount)' that deducts 'amount' from 'self.balance'. A developer writes a subclass 'SavingsAccount' that overrides 'withdraw' to add a penalty if balance drops below minimum. Which design pattern is being used?
Quick Answer
The correct answer is method overriding, because the SavingsAccount subclass redefines the withdraw method from BankAccount to add penalty logic while preserving the same method signature. This is the defining characteristic of method overriding in Python: a subclass provides its own specific implementation of a method already defined in its superclass, allowing dynamic dispatch at runtime to call the appropriate version based on the object’s actual type. On the Certified Associate Python Programmer PCAP exam, this concept tests your understanding of inheritance and polymorphism, often appearing in questions that ask you to identify the design pattern when a subclass alters a parent method’s behavior. A common trap is confusing overriding with overloading—remember that Python does not support true method overloading; overriding always involves the same method name and parameters. Memory tip: think “override = replace the parent’s version” and “overload = same name, different arguments (not Python’s style).”
⚠ Common exam trap
Many candidates confuse inheritance (the relationship) with method overriding (the specific technique), leading them to select 'Inheritance' instead of 'Method overriding' when the question explicitly describes a subclass redefining a parent method.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Method overriding
Method overriding is the mechanism where a subclass provides a specific implementation of a method that is already defined in its superclass. In this scenario, SavingsAccount overrides the withdraw method from BankAccount to add penalty logic, which is the defining characteristic of method overriding in Python.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Composition
Why it's wrong here
Composition involves 'has-a' relationships, not overriding.
- ✗
Aggregation
Why it's wrong here
Aggregation is a form of composition.
- ✓
Method overriding
Why this is correct
The subclass provides a specific implementation of the inherited method.
- ✗
Inheritance
Why it's wrong here
Inheritance is the mechanism, but the question asks about the pattern.
Go deeper
Related to this question
About these practice questions
This PCAP question is part of Courseiva's 169-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
Same concept, more angles
1 more way this is tested on PCAP
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. An engineer is debugging an application that uses inheritance. The base class 'Vehicle' defines a method 'start()' that prints 'Vehicle started'. The subclass 'Car' overrides 'start()' to print 'Car started'. The code contains a function that accepts a Vehicle object and calls 'start()'. What is the output if a Car object is passed?
medium- A.'Car started Vehicle started'
- B.'Vehicle started'
- ✓ C.'Car started'
- D.AttributeError
Why C: When a Car object is passed to a function expecting a Vehicle reference, Python uses dynamic dispatch (late binding) to call the overridden `start()` method defined in the Car class. Since the actual runtime type is Car, the overridden version executes, printing 'Car started'. This is a fundamental principle of polymorphism in Python.
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This PCAP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCAP exam.