Courseiva

PCAP Object-Oriented Programming Practice Question

Which of the following is true regarding Python's method resolution order (MRO) in multiple inheritance?

⚠ Common exam trap

Many exam-takers assume the MRO follows a simple depth-first, left-to-right order (as in older Python versions or other languages), but Python's C3 algorithm can produce a different order to handle diamond inheritance correctly.

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

✓

The MRO is computed using the C3 linearization algorithm, ensuring that each class appears before its parents and that monotonicity is preserved.

Python's method resolution order (MRO) is computed using the C3 linearization algorithm. This algorithm ensures that each class appears before its parents and that monotonicity is preserved, meaning the order of class precedence does not change when new subclasses are introduced. This is essential for resolving method calls in multiple inheritance scenarios, particularly with diamond inheritance.

Answer analysis

Option-by-option breakdown

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

  • ✓

    The MRO is computed using the C3 linearization algorithm, ensuring that each class appears before its parents and that monotonicity is preserved.

    Why this is correct

    C3 linearization is the algorithm Python uses to compute the MRO at class creation time. It guarantees that every class appears before any of its parents in the linearization and that the local precedence order of bases is preserved across the entire hierarchy, a property called monotonicity. This ensures that `super()` calls follow a consistent, predictable order even in complex diamond inheritance, avoiding duplicate executions and inconsistent dispatch.

  • ✗

    The MRO is always the same as the order of base classes specified in the class statement.

    Why it's wrong here

    The MRO is not necessarily identical to the order of base classes listed in the class statement. For simple hierarchies the two may coincide, but in multiple inheritance C3 merges the parent MROs with the local base order, reordering classes to respect monotonicity. For example, class D(B, C) where both inherit A produces D, B, C, A, not the naive D, B, A, C that the base order alone would suggest.

  • ✗

    The MRO can be changed at runtime by modifying the __bases__ attribute of a class.

    Why it's wrong here

    The `__bases__` attribute of a class is read-only in Python, so it cannot be modified after class creation, nor can the MRO be changed at runtime. Attempting to assign to `__bases__` raises a TypeError, and the MRO is stored in `__mro__` as a fixed tuple. Class creation is the only point at which the MRO is computed, via C3, and it remains immutable thereafter.

  • ✗

    The MRO is determined by the order of base classes in the class definition, using a depth-first, left-to-right search without consideration of diamond inheritance.

    Why it's wrong here

    Although it may resemble depth-first, left-to-right traversal, Python's MRO is computed with C3 linearization, which explicitly handles diamond inheritance by merging parent MROs and enforcing local precedence. A naive DFLR traversal would fail in diamond patterns because it could place a base class after a class that depends on it, violating monotonicity. Python's actual algorithm considers the entire hierarchy and produces a consistent, repeatable order that DFLR without such considerations cannot guarantee.

Visual reference

Client Recursive Resolver Root DNS (13 root servers) TLD DNS (.com, .org, …) Authoritative example.com query IP addr answer

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 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.