Courseiva
Object-Oriented Programming →mediumMultiple Choice

PCAP Object-Oriented Programming Practice Question

A team is developing a system that must handle different types of documents (PDF, Word, etc.). Each document type has a unique parsing method. To avoid massive conditional logic, which OOP concept should be applied?

⚠ Common exam trap

Python Institute often tests the distinction between inheritance and polymorphism: candidates mistakenly think inheritance alone solves the problem, but without polymorphic method dispatch, you still need conditional logic to handle different types.

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

✓

Polymorphism

Polymorphism allows different document types (PDF, Word, etc.) to be treated uniformly through a common interface (e.g., a `parse()` method) while each class implements its own parsing logic. This eliminates the need for conditional statements (like `if type == 'PDF'`) because the correct method is resolved at runtime via dynamic dispatch, which is exactly what the team needs to avoid massive conditional logic.

Answer analysis

Option-by-option breakdown

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

  • ✓

    Polymorphism

    Why this is correct

    Polymorphism (specifically subtype polymorphism) is correct because it allows a common interface or base-class reference to invoke different implementations depending on the actual runtime type. In a system handling different types, a single method call can be dispatched dynamically to the appropriate subclass override, which directly addresses the need for type-specific behavior. This is the OOP feature specifically designed to let objects of different classes respond to the same message in distinct ways.

  • ✗

    Encapsulation

    Why it's wrong here

    Encapsulation is not the correct answer because it focuses on bundling data with the methods that operate on it and restricting direct access to an object's internal state, typically via private attributes and public accessors. While encapsulation protects data integrity and reduces coupling, it does not provide any mechanism for different types to exhibit different behavior through a shared interface. Handling different types primarily requires behavioral variation, which encapsulation alone cannot deliver.

  • ✗

    Inheritance

    Why it's wrong here

    Inheritance is not the correct answer because it establishes a parent-child 'is-a' relationship, enabling code reuse and propagation of attributes/methods from a base class to subclasses. However, simply inheriting methods does not automatically produce different behavior for each type; a subclass may inherit a method unchanged, resulting in identical behavior. Despite common misconceptions, inheritance only enables behavior variation when subclasses override inherited methods — and that overriding, along with runtime dispatch, is the essence of polymorphism, not inheritance itself.

  • ✗

    Abstraction

    Why it's wrong here

    Abstraction is not the correct answer because it is about simplifying complexity by exposing only relevant high-level operations and hiding implementation details, often through abstract classes or interfaces. While abstraction can define a common contract for different types (e.g., an abstract method signature), it does not decide how each concrete type implements that contract. Abstraction lays the groundwork, but the actual runtime selection of a specific type's implementation is performed by polymorphism, making it the direct solution.

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

Courseiva writes every PCAP question from scratch — 421 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. 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.