PCAP Object-Oriented Programming Practice Question
Which of the following best describes the use of the @abstractmethod decorator in Python?
⚠ Common exam trap
The PCAP exam often tests the distinction between 'must be overridden' and 'can be overridden' — the trap here is that candidates confuse @abstractmethod with a method that simply raises NotImplementedError, which does not enforce overriding at instantiation time.
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
✓
It indicates that a method must be overridden in any non-abstract subclass.
The @abstractmethod decorator, when used in conjunction with a metaclass like ABC (Abstract Base Class) or by inheriting from ABC, declares a method as abstract. This forces any concrete (non-abstract) subclass to provide an override of that method; otherwise, Python raises a TypeError at instantiation time. Option B correctly captures this mandatory override requirement.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
It automatically provides a default implementation for a method.
Why it's wrong here
The @abstractmethod decorator does not supply any implementation; it marks a method as intentionally lacking a concrete body in the abstract base class. A true default implementation would be written as a normal method with code and then optionally overridden, but an abstract method is declared precisely because no meaningful default exists. When a subclass fails to override it, the class remains abstract and cannot be instantiated, so no default behavior is ever provided.
- ✓
It indicates that a method must be overridden in any non-abstract subclass.
Why this is correct
Decorating a method with @abstractmethod registers it in the class's __abstractmethods__ set, and the ABCMeta metaclass enforces that every concrete (non-abstract) subclass must provide an overriding implementation. This enforcement happens at instantiation time: attempting to create an instance of a subclass that leaves any abstract method unimplemented raises TypeError. Thus the decorator expresses a contract that subclasses must fulfill, not a prefix to an automatically inherited implementation.
- ✗
It creates a method that can be called without an instance.
Why it's wrong here
A method callable without an instance is the effect of @staticmethod or @classmethod, both of which bind the method to the class rather than to an instance. In contrast, an abstract method is an ordinary instance method; it still expects self as its first parameter and becomes callable only after a concrete subclass overrides it, at which point an instance is required. Confusing @abstractmethod with static or class decorators overlooks the role of self and the instantiation contract.
- ✗
It raises AttributeError if the method is called.
Why it's wrong here
Calling an abstract method directly does not raise AttributeError; if the method is somehow reached, its body typically contains pass or raises NotImplementedError, so a call would return None or raise that explicit exception. The real TypeError raised by @abstractmethod occurs earlier, when code tries to instantiate a class whose __abstractmethods__ set is non-empty, not when the method itself is invoked. AttributeError would indicate a missing attribute entirely, which is not how Python resolves inheritable method names.
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 →
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.