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
Inheritance order does not affect the requirement to implement abstract methods.
- ✓
Implement the area() method in Rectangle.
Why this is correct
All abstract methods must be implemented in a concrete subclass.
- ✗
Use a class decorator @abstractmethod for Rectangle.
Why it's wrong here
Decorating a class with @abstractmethod is not valid syntax; it's used on methods.
- ✗
Remove the abstract method from Shape by removing the @abstractmethod decorator.
Why it's wrong here
This changes the base class design and may affect other subclasses.
Visual reference
Go deeper
Related to this question
About these practice questions
One of 169 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.