Java

  1. Home
  2. Computing & Technology
  3. Java
photo of Paul Leahy

Paul's Java Blog

By Paul Leahy, About.com Guide to Java

Accessors and Mutators

Friday October 24, 2008

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.

Comments

No comments yet. Leave a Comment

Leave a Comment

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

Discuss

Community Forum

Explore Java

About.com Special Features

Java

  1. Home
  2. Computing & Technology
  3. Java

©2009 About.com, a part of The New York Times Company.

All rights reserved.