Abstract Method Implementation in Python Subclasses
A developer is working on a class hierarchy for geometric shapes. They have a base class Shape with an abstract method area(). They also have a mixin class Drawable that provides a method draw(). They want to create a class Rectangle that inherits from both Shape and Drawable. However, they encounter a TypeError when trying to instantiate Rectangle because the abstract method area() is not implemented. Which action should they take to resolve this?
Quick Answer
The correct action is to implement the area() method in the Rectangle class. This is required because Shape inherits from Python’s Abstract Base Class (ABC) and declares area() as an abstract method using the @abstractmethod decorator; any concrete subclass must override all inherited abstract methods before it can be instantiated. Without this implementation, Rectangle remains abstract, and Python raises a TypeError at instantiation time. On the Certified Associate Python Programmer PCAP exam, this concept tests your understanding of abstract method implementation in subclass relationships, especially when multiple inheritance is involved—a common trap is forgetting that a mixin like Drawable does not fulfill the abstract method requirement. To remember: an abstract method is a contract—every concrete child must sign it by providing its own implementation.
⚠ Common exam trap
Python Institute often tests the misconception that changing inheritance order or using decorators can bypass the abstract method requirement, when in fact the only valid fix is to implement the abstract method in the concrete subclass.
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
✓
Implement the area() method in Rectangle.
The abstract method area() declared in the Shape base class must be implemented in any concrete subclass. In Python, a class that inherits from an ABC (Abstract Base Class) with an abstract method cannot be instantiated until that method is overridden. By providing an implementation of area() in Rectangle, the class becomes concrete and can be instantiated without raising a TypeError.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Change the inheritance order to Drawable first, then Shape.
Why it's wrong here
Reordering bases does not implement area(); Python still raises TypeError because Rectangle remains abstract. MRO changes only affect attribute resolution, not abstractmethod enforcement. Reordering is tempting when resolving metaclass or method-resolution conflicts, but here the missing concrete area() implementation is the actual cause.
- ✓
Implement the area() method in Rectangle.
Why this is correct
Implementing area() in Rectangle satisfies the abstract-method contract inherited from Shape, so instantiation no longer raises TypeError. Python's ABCMeta blocks instantiation while any abstract method remains unimplemented; providing a concrete override in the subclass clears that check. Multiple inheritance from Drawable is unaffected, since mixins impose no abstract requirements here.
- ✗
Use a class decorator @abstractmethod for Rectangle.
Why it's wrong here
@abstractmethod is a method decorator, not a class decorator; applying it to Rectangle is invalid and does not supply the missing area() implementation. It is tempting because it appears to formalise the abstract relationship, but Rectangle needs a concrete area() method, not a decorator that leaves it uninstantiable.
- ✗
Remove the abstract method from Shape by removing the @abstractmethod decorator.
Why it's wrong here
Removing @abstractmethod lets Shape be instantiated directly and silently drops the contract requiring subclasses to implement area(), masking the real defect. It is tempting as a quick fix to clear the TypeError, but abstract base classes exist precisely to force concrete implementations; the correct action is to implement area() in Rectangle.
Visual reference
Go deeper
Related to this question
About these practice questions
One of 421 original PCAP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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. A company is developing a scientific simulation framework where many different solvers must be interchangeable. The framework should enforce that each solver implements methods 'initialize' and 'step'. Developers want to use abstract base classes. Which approach should the team take to ensure that any subclass of 'Solver' cannot be instantiated unless it defines both methods?
medium- A.Define an interface in a separate module and check using isinstance
- B.Use @abstractmethod without inheriting from ABC
- ✓ C.Inherit from ABC and decorate both methods with @abstractmethod
- D.Define Solver with methods that raise NotImplementedError
Why C: Inheriting from `ABC` (from the `abc` module) and decorating both `initialize` and `step` with `@abstractmethod` enforces that any concrete subclass must override these methods. Attempting to instantiate a subclass that does not implement all abstract methods raises a `TypeError`, ensuring compile-time-like safety at runtime.
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.