Written by the Fiveable Content Team โข Last updated September 2025
Verified for the 2026 exam
Verified for the 2026 examโขWritten by the Fiveable Content Team โข Last updated September 2025
Definition
A set method, also known as a mutator, is a method in object-oriented programming that allows the modification of an object's attributes or properties. It is used to update the values of instance variables within an object.
A get method, also known as an accessor, is used to retrieve or access the value of an attribute or property from an object. It allows other parts of the program to obtain information about an object without directly modifying its internal state.
Encapsulation is one of the fundamental principles in object-oriented programming. It refers to bundling data and methods together into a single unit called an object. Set methods are often used in encapsulation to control access to and modification of data within objects.
An instance variable, also known as a member variable or attribute, is a variable declared inside a class but outside any methods. Each instance/object created from that class has its own copy of these variables. Set methods are commonly used to modify the values stored in instance variables.