Fiveable
Fiveable

Accessor Methods

Definition

Accessor methods, also known as getter methods, are a type of method in object-oriented programming that allows the retrieval of the value of an object's private data member. They provide read-only access to the internal state of an object.

Analogy

Think of accessor methods like a vending machine. You can't directly access the snacks inside the machine, but you can use the buttons on the outside to retrieve information about what snacks are available and their prices.

Related terms

Getter Methods: Getter methods are a specific type of accessor method that retrieves the value of a specific attribute or property of an object.

Setter Methods: Setter methods, also known as mutator methods, allow modification or update to an object's private data members.

Encapsulation: Encapsulation is a principle in OOP that combines data and functions into a single unit called an object, where data is hidden from external access and can only be accessed through defined public interfaces (such as accessor and mutator methods).

collegeable - rocket pep

Are you a college student?

  • Study guides for the entire semester

  • 200k practice questions

  • Glossary of 50k key terms - memorize important vocab



© 2024 Fiveable Inc. All rights reserved.

AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.


© 2024 Fiveable Inc. All rights reserved.

AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.