nerdexam
Oracle

1Z0-808 · Question #81

Which three statements are benefits of encapsulation?

The correct answer is A. allows a class implementation to change without changing t he clients B. protects confidential data from leaking out of the objects D. enables the class implementation to protect its invariants. Encapsulation's three core benefits are about control and protection: it lets you change internal implementation without breaking client code (A), because clients interact only through the public interface; it hides sensitive data behind private access modifiers (B), preventing…

Working with Methods and Encapsulation

Question

Which three statements are benefits of encapsulation?

Options

  • Aallows a class implementation to change without changing t he clients
  • Bprotects confidential data from leaking out of the objects
  • Cprevents code from causing exceptions
  • Denables the class implementation to protect its invariants
  • Epermits classes to be combined into the same package
  • Fenables multiple instances of the same class to be created safely

How the community answered

(25 responses)
  • A
    88% (22)
  • C
    8% (2)
  • F
    4% (1)

Explanation

Encapsulation's three core benefits are about control and protection: it lets you change internal implementation without breaking client code (A), because clients interact only through the public interface; it hides sensitive data behind private access modifiers (B), preventing external code from reading or corrupting it directly; and it enforces class invariants (D) by funneling all state changes through controlled methods that can validate inputs and maintain consistency.

The distractors are wrong because: C is false - encapsulation does not prevent exceptions, which can arise from logic errors regardless of access control; E describes package organization, which is a separate concept unrelated to encapsulation; F describes general class instantiation behavior, which exists independent of whether a class is encapsulated or not.

Memory tip: Think of encapsulation as a capsule (pill) - the outer shell controls what goes in and out (interface), protects the contents (data hiding), and maintains the formula inside (invariants). Anything about preventing runtime errors or organizing files is outside what a capsule does.

Topics

#Encapsulation#Data Hiding#Class Design#Invariant Protection

Community Discussion

No community discussion yet for this question.

Full 1Z0-808 Practice