Courseiva

PCAP Object-Oriented Programming Practice Question

A developer writes a class `Logger` with a method `log(self, message)`. They want to ensure that when `Logger` is subclassed, any override of `log` must call the parent's `log` method. Which technique best enforces this requirement in Python?

⚠ Common exam trap

The trap here is assuming that abstract methods or other decorators can enforce that a subclass calls the parent method, when they cannot.

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

✓

There is no built-in Python mechanism to enforce that an override calls the parent method; it must be handled by convention and documentation.

Python's philosophy emphasizes flexibility and developer responsibility. There is no language-level construct that forces a subclass to call `super().log()`. Techniques like abstract methods ensure implementation but not invocation of the parent. Metaclasses or descriptors could be used to add checks, but they are not built-in and are overly complex. The correct answer recognizes that enforcement is not a built-in feature.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✓

    There is no built-in Python mechanism to enforce that an override calls the parent method; it must be handled by convention and documentation.

    Why this is correct

    Python does not provide a built-in way to enforce that a subclass override calls the superclass method. This is by design, as Python relies on conventions and developer discipline. While design patterns like the template method can encourage it, they do not enforce it. The correct answer acknowledges this limitation.

  • ✗

    Decorate the parent's `log` method with `@abstractmethod`.

    Why it's wrong here

    `@abstractmethod` is used with `ABCMeta` to declare a method that must be overridden in subclasses. It does not enforce that the override calls the parent method. It only ensures the method is implemented. This technique does not meet the requirement of forcing a call to the parent's implementation.

  • ✗

    Use a metaclass that wraps the `log` method to check if `super().log` was called.

    Why it's wrong here

    A metaclass could theoretically intercept method calls, but detecting whether `super().log` was invoked is complex and not a standard Python pattern. It would require deep introspection and is error-prone. This is not a recommended or practical solution for enforcing parent method calls.

  • ✗

    Define `log` in the parent class to raise `NotImplementedError` and document that subclasses must call `super().log()`.

    Why it's wrong here

    Raising `NotImplementedError` would prevent the parent method from doing any useful work and would not enforce that subclasses call it. It merely indicates that the method should be overridden. Documentation is not enforcement. This approach does not guarantee the parent method is called.

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 →

How Courseiva writes practice questions · Editorial policy

JA

Written and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official Python Institute exam blueprint

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.