Courseiva
Object-Oriented ProgrammingeasyMultiple ChoiceObjective-mapped

1Z0-811 Object-Oriented Programming Practice Question

A junior developer created a class 'BankAccount' with public fields for balance and account number. After deployment, users are able to set negative balances, causing issues. Which OOP principle should have been applied to prevent this?

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

Encapsulation

Encapsulation involves making fields private and providing controlled access via methods. By encapsulating the balance field, a setter method can validate that the balance is not set to a negative value, preventing the issue. Option A (Inheritance) is about code reuse, not data hiding. Option C (Abstraction) is about hiding complexity, not enforcing validation. Option D (Polymorphism) is about methods behaving differently, not data protection.

Answer analysis

Option-by-option breakdown

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

  • Inheritance

    Why it's wrong here

    Inheritance does not prevent public field access.

  • Encapsulation

    Why this is correct

    Encapsulation allows controlled access through methods with validation.

  • Abstraction

    Why it's wrong here

    Abstraction is about hiding implementation, not data validation.

  • Polymorphism

    Why it's wrong here

    Polymorphism does not restrict direct field access.

About these practice questions

This 1Z0-811 question is part of Courseiva's 481-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 →

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.