Courseiva
Object-Oriented ProgrammingmediumMultiple ChoiceObjective-mapped

1Z0-811 Object-Oriented Programming Practice Question

A team is designing a system where a 'Report' class can be generated in different formats (PDF, Excel, HTML). They want to avoid modifying the Report class when adding new formats. Which OOP principle or pattern should they use?

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

Omposition (often implemented via the Strategy pattern), which allows the Report class to delegate format generation to separate strategy objects. This adheres to the Open/Closed Principle: the Report class is closed for modification but open for extension. Adding a new format only requires creating a new strategy class without altering the Report class. Option B (Composition) is correct. Option A (Method Overloading) is incorrect because it would require adding a new overloaded method for each format in the Report class, violating the goal of not modifying it. Option C (Inheritance) is incorrect because it would create a rigid hierarchy where each format is a subclass of Report, leading to tight coupling and difficulty in adding new formats without modifying existing code. Option D (Singleton) is incorrect because it ensures a single instance, which does not address the need for flexible format generation.

Answer analysis

Option-by-option breakdown

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

  • Method Overloading

    Why it's wrong here

    Overloading is compile-time and not suitable for runtime format selection.

  • Composition

    Why this is correct

    Composing Report with a formatter interface allows adding formats without modifying Report.

  • Inheritance

    Why it's wrong here

    Inheritance would require creating subclasses for each format, modifying Report if new formats are added.

  • Singleton

    Why it's wrong here

    Singleton controls instantiation but does not support extensibility.

About these practice questions

One of 481 original 1Z0-811 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 1Z0-811 practice question is part of Courseiva's free Oracle 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 1Z0-811 exam.