PCAP Object-Oriented Programming Practice Question
A team is implementing a shape hierarchy with a base class `Shape` that should have an `area()` method. They want to ensure that every subclass must provide its own implementation of `area()`. Which approach should they use?
⚠ Common exam trap
Python Institute often tests the distinction between raising `NotImplementedError` (a runtime-only check) and using `@abstractmethod` (which prevents instantiation of incomplete subclasses), leading candidates to mistakenly choose Option A because they think 'raising an error' is sufficient for enforcement.
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
✓
Use `@abstractmethod` from the `abc` module to declare `area()` as abstract.
The `abc` module provides the `ABCMeta` metaclass and the `@abstractmethod` decorator, which together enforce that any concrete subclass must override the abstract method. If a subclass fails to implement `area()`, Python raises a `TypeError` at instantiation time, ensuring the design contract is upheld. This is the standard Pythonic way to define abstract base classes and enforce method implementation in subclasses.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Define `area()` in `Shape` and have it raise `NotImplementedError`.
Why it's wrong here
Defining `area()` to raise `NotImplementedError` turns the missing implementation into a runtime exception, but nothing prevents code from instantiating `Shape` or a subclass that never overrides the method—the error only appears when someone calls `area()`. This approach relies on developer discipline and, because there is no `abc` machinery, the class hierarchy gives no early feedback at construction time. It is a common idiom but not a language-enforced abstraction.
- ✗
Use a class method that must be overridden.
Why it's wrong here
Using a class method—even one that raises `NotImplementedError` inside—does not create an abstract contract; `@classmethod` merely changes how the method receives its caller and does not trigger any metaclass check. A subclass can inherit or ignore the class method without error, and `Shape` still remains concrete and instantiable. There is no 'must be overridden' semantics available through `classmethod` alone.
- ✗
Define `area()` as a property that raises an error.
Why it's wrong here
Defining `area()` as a property whose getter raises an error only affects attribute access: `s.area` would raise at that moment, but creating `Shape()` succeeds normally. A property is a descriptor for computed attributes, not a mechanism for declaring abstract behavior, and subclasses are not required to override it. This approach also conflates interface enforcement with attribute API design.
- ✓
Use `@abstractmethod` from the `abc` module to declare `area()` as abstract.
Why this is correct
Decorating `area()` with `@abstractmethod` inside an `ABC` subclass installs `ABCMeta` as the metaclass, which tracks the class's `__abstractmethods__` set. If any abstract method remains unimplemented, `ABCMeta.__call__` refuses to instantiate the class (`TypeError`), and any concrete subclass must override `area()` (or remain abstract itself). This gives construction-time enforcement rather than deferring errors to method calls.
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 →
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.