Back to Writing Classes

Lesson PreviewLesson 5 of 10 in this unit

5.5 Mutator Methods

Part of Writing Classes in AP® Computer Science A. Read the opening section, then create a free account for the full interactive lesson, practice, and progress tracking.

Mutator methods, also called setter methods, allow us to modify private fields in a controlled and predictable way. They help us achieve encapsulation, a principle that protects an object's internal state and ensures its integrity by controlling how external code interacts with its data.

Continue the full lesson in Stellar

Create a free account to unlock the remaining sections, checkpoints, course practice, and progress tracking for AP® Computer Science A.