What are setters and getters?

1 post / 0 new
What are setters and getters?


A setter is a method used to change the value of an attribute and a getter is a method used to get the value of an attribute. There is a standard naming convention for getters and setters, but Java compiler won't complain even otherwise.

private String name;

public String getName() {

  return name;


public void setName(String name) {



Here getName and setName are the getter and setter for the variable 'name' respectively. Since this is a standard naming convention, many IDEs like eclipse will generate it for you in this form.

Was it useful?

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!