1. Computing

Accessors and Mutators

By October 24, 2008

Follow me on:

Following the theme of articles on object-oriented programming, today I'm looking at how to program accessor and mutator methods in Java. The role of accessors and mutators are to return and set the values of an object's state.

Sometimes it necessary to provide a way to gain access to values that make up the state of a object. The calling code might need to know what the value is or to modify it. The most direct way that still enforces data encapsulation is through the use of accessors and mutators.

No comments yet. Leave a Comment
Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

©2014 About.com. All rights reserved.