Unit 3 Cycle 2 Day 19: I/II/III: Encapsulation Principles

Unit 3 Advanced (Cycle 2) Day 19 of 28 Advanced

I/II/III: Encapsulation Principles

Section 3.9 — Scope and Access

Key Concept

I/II/III encapsulation principles questions test the rules and benefits of hiding implementation details. Core principles include: instance variables should be private, public methods provide controlled access, changes to internal representation should not break external code, and accessor methods may return copies rather than references to mutable objects. Each statement asserts a principle or its violation. The AP exam tests both the rules themselves and their practical implications for code design.

Consider these statements about encapsulation.

I. Private instance variables prevent external classes from directly modifying object state. II. A class with all public instance variables is properly encapsulated. III. Accessor methods allow reading private data without exposing the implementation.

Which of the statements are true?

Answer: (A) I and III only

I: TRUE. Private fields enforce controlled access.
II: FALSE. Public instance variables break encapsulation.
III: TRUE. Getters provide read access without exposing how data is stored.

Why Not the Others?

(B) II is false. Public instance variables are the opposite of encapsulation.

(C) III is also true. Accessors are a key part of encapsulation.

(D) II is false. Encapsulation requires private fields, not public ones.

Common Mistake

Encapsulation = private data + public methods. Public instance variables allow anyone to change the data without validation, breaking encapsulation.

AP Exam Tip

The AP exam expects: private instance variables, public constructors, public accessors/mutators. This is the standard encapsulation pattern.

Review this topic: Section 3.9 — Scope and Access • Unit 3 Study Guide

More Practice

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.