PCAP Object-Oriented Programming Practice Question
A developer is designing a system where a `Car` class needs to reuse functionality from `Engine` and `Transmission` without creating a deep hierarchy. Which OOP principle should be applied?
⚠ Common exam trap
Python Institute often tests the distinction between 'is-a' (inheritance) and 'has-a' (composition) relationships, and the trap here is that candidates mistakenly choose multiple inheritance (Option C) because they think reusing functionality requires inheritance, ignoring the complexity and the explicit instruction to avoid a deep hierarchy.
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
✓
Composition over inheritance.
'Composition over inheritance,' is correct because it advocates building the Car class by composing it with Engine and Transmission objects (has-a relationships) rather than inheriting from them. This avoids a deep class hierarchy and provides flexibility to change or swap components at runtime, which is a key design principle in Python and OOP.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Aggregation, where Car is part of Engine.
Why it's wrong here
Aggregation implies a whole-part relationship where the container (Engine) would hold the contained item (Car). Here the direction is exactly backwards: a Car contains an Engine, not the reverse. Even if we corrected the direction, aggregation alone is a weak 'has-a' relationship and does not define how Car delegates to Engine's functionality; composition with explicit ownership and lifecycle management is the appropriate choice.
- ✗
Singleton pattern for Engine.
Why it's wrong here
The Singleton pattern solves a different problem: it ensures a class has only one instance and provides a global access point. It says nothing about how Car should reuse or incorporate the behavior of an Engine and Transmission, and forcing a single Engine instance would prevent each Car from having its own engine. As a creational pattern, Singleton is orthogonal to the structural relationship needed here.
- ✗
Multiple inheritance to inherit from both.
Why it's wrong here
Using multiple inheritance would make Car a subclass of both Engine and Transmission, implying that a Car is-a Engine and a Transmission rather than has-a. This rigid is-a hierarchy exposes Engine and Transmission internals to Car, creates a diamond problem if those classes share methods, and makes it hard to swap components at runtime. Composition avoids these pitfalls by delegating responsibilities to injected components.
- ✓
Composition over inheritance.
Why this is correct
Composition over inheritance correctly models the real-world relationship: a Car has-an Engine and has-a Transmission. By storing these as separate member objects (often passed via constructor or setter), Car delegates behavior such as start(), shift(), and stop() to its components. This allows the engine or transmission to be replaced or mocked independently, promoting loose coupling, testability, and adherence to the single-responsibility principle.
Go deeper
Related to this question
About these practice questions
This PCAP question is part of Courseiva's 421-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.