Question 359 of 511
Object-Oriented ProgramminghardMultiple ChoiceObjective-mapped

Quick Answer

The correct answer is D, B, C, A, object. This order is determined by Python’s C3 linearization algorithm, which resolves the diamond inheritance pattern by merging the linearizations of D’s parents—B and C—while preserving local precedence order and monotonicity. For class D(B, C), the merge of L(B) = [B, A, object] and L(C) = [C, A, object] with the parent list [B, C] yields D first, then B (since it appears first in the parent list), then C, then A (the common ancestor), and finally object. On the PCAP exam, this tests your understanding of how Python avoids ambiguity in multiple inheritance, often appearing as a code-tracing question where the trap is assuming depth-first, left-to-right order (which would give D, B, A, C, object). A handy memory tip: think of C3 as “children before parents, and left parents before right parents”—so D, then B before C, then their shared parent A, then object.

PCAP Object-Oriented Programming Practice Question

This PCAP practice question tests your understanding of object-oriented programming. Read the scenario carefully and evaluate each option against the stated constraints before committing to an answer. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.

Consider the following code snippet: 'class A: pass; class B(A): pass; class C(A): pass; class D(B, C): pass'. What is the Method Resolution Order (MRO) for class D according to the C3 linearization algorithm used by Python?

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

D, B, C, A, object

The C3 linearization algorithm merges the linearizations of D's parents (B and C) with their parent list, respecting the local precedence order and monotonicity. For class D(B, C), the MRO is computed as D + merge(L(B), L(C), [B, C]), where L(B) = B, A, object and L(C) = C, A, object. The merge yields D, B, C, A, object, which is the correct MRO.

Key principle: Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Answer analysis

Option-by-option breakdown

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

  • D, B, A, C, object

    Why it's wrong here

    This would be depth-first but does not satisfy monotonicity.

  • D, B, C, A

    Why it's wrong here

    MRO always ends with object.

  • D, B, A, object, C

    Why it's wrong here

    C is a parent and must appear before object.

  • D, B, C, A, object

    Why this is correct

    Correct linearization based on C3.

    Related concept

    Read the scenario before looking for a memorised answer.

Common exam traps

Common exam trap: answer the scenario, not the keyword

Python Institute often tests the misconception that Python uses depth-first left-to-right resolution (like in old-style classes), leading candidates to pick Option A (D, B, A, C, object) instead of the correct C3 linearization result.

Detailed technical explanation

How to think about this question

The C3 linearization algorithm ensures consistent MRO by merging parent linearizations using a head-tail comparison, rejecting any head that appears in the tail of another list. This prevents the 'diamond problem' and guarantees that subclasses override methods in a predictable order. In practice, understanding MRO is critical when using cooperative multiple inheritance with super(), as the order determines which method is called next.

KKey Concepts to Remember

  • Read the scenario before looking for a memorised answer.
  • Find the constraint that changes the correct option.
  • Eliminate answers that are true in general but not in this case.

TExam Day Tips

  • Watch for words such as best, first, most likely and least administrative effort.
  • Review why wrong options are wrong, not only why the correct option is correct.

Key takeaway

Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Real-world example

How this comes up in practice

A media company stores terabytes of video archives that are accessed once a year for audit purposes. Moving these objects to a cold storage tier (Azure Archive, S3 Glacier, or Google Nearline) costs a fraction of hot storage. Questions like this test whether you understand storage tiers, access frequency tradeoffs, and retrieval latency requirements.

What to study next

Got this wrong? Here's your next step.

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

Related practice questions

Related PCAP practice-question pages

Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.

Practice this exam

Start a free PCAP practice session

Short sessions build daily habit. Longer sessions build exam-day stamina. Try a timed session to simulate real conditions.

FAQ

Questions learners often ask

What does this PCAP question test?

Object-Oriented Programming — This question tests Object-Oriented Programming — Read the scenario before looking for a memorised answer..

What is the correct answer to this question?

The correct answer is: D, B, C, A, object — The C3 linearization algorithm merges the linearizations of D's parents (B and C) with their parent list, respecting the local precedence order and monotonicity. For class D(B, C), the MRO is computed as D + merge(L(B), L(C), [B, C]), where L(B) = B, A, object and L(C) = C, A, object. The merge yields D, B, C, A, object, which is the correct MRO.

What should I do if I get this PCAP question wrong?

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

What is the key concept behind this question?

Read the scenario before looking for a memorised answer.

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

5 more ways 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. Consider the following code: class A: x = 1; class B(A): pass; class C(A): x = 2; class D(B, C): pass. What is D.x?

medium
  • A.AttributeError
  • B.1
  • C.2
  • D.(1, 2) tuple

Why C: Option C is correct because Python's method resolution order (MRO) for class D, which uses multiple inheritance, follows the C3 linearization algorithm. The MRO for D is D, B, C, A, and since C defines x = 2, that attribute overrides the x = 1 from A in the inheritance chain, so D.x resolves to 2.

Variation 2. Consider the following class hierarchy: class A: def method(self): return 'A'; class B(A): pass; class C(A): def method(self): return 'C'; class D(B, C): pass. What is the output of D().method() according to Python's MRO?

medium
  • A.'B'
  • B.TypeError
  • C.'A'
  • D.'C'

Why D: Python's MRO (Method Resolution Order) for class D(B, C) is computed using the C3 linearization algorithm, which respects the local precedence order and monotonicity. The MRO for D is D -> B -> C -> A, so D().method() resolves to C.method(), returning 'C'. Option D is correct because C is the first class in the MRO that defines method().

Variation 3. A developer defines a class hierarchy with multiple inheritance: class A, class B(A), class C(A), class D(B,C). The method 'm' is defined only in A. What is the method resolution order for D according to the C3 linearization algorithm?

medium
  • A.D -> B -> A -> object
  • B.D -> B -> C -> A -> object
  • C.D -> B -> C -> A
  • D.D -> B -> A -> C

Why C: C is correct because the C3 linearization algorithm merges the linearizations of parent classes while preserving local precedence order and monotonicity. For class D(B, C), the linearization is D + merge(L(B), L(C), [B, C]). L(B) = B, A, object; L(C) = C, A, object. Merging yields D, B, C, A, object (object is often omitted in option lists). This respects that B precedes C in D's bases and that A appears after both B and C.

Variation 4. Given: class A: def method(self): print('A'); class B(A): def method(self): super().method(); print('B'); class C(A): def method(self): super().method(); print('C'); class D(B, C): pass. What is printed by D().method()?

medium
  • A.A B C
  • B.A C B
  • C.C A B
  • D.B A C

Why B: Option B is correct because Python's MRO (Method Resolution Order) for class D, which inherits from B and C (both inheriting from A), follows the C3 linearization algorithm. The MRO for D is D -> B -> C -> A, so calling D().method() triggers B.method(), which calls super().method() (resolving to C.method()), which calls super().method() (resolving to A.method()), printing 'A', then back to C prints 'C', then back to B prints 'B', resulting in 'A C B'.

Variation 5. Refer to the exhibit. Which of the following correctly shows the MRO of class D?

medium
  • A.[D, B, C, A, object]
  • B.[D, A, B, C, object]
  • C.[D, B, A, C, object]
  • D.[D, C, B, A, object]

Why A: Option A is correct because Python's Method Resolution Order (MRO) for class D, which inherits from B and C (where B inherits from A and C inherits from A), follows the C3 linearization algorithm. The MRO is computed as D -> B -> C -> A -> object, ensuring that each class appears before its parents and that the order respects the local precedence order of D's bases (B before C).

Keep practising

More PCAP practice questions

Last reviewed: Jun 30, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

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.