Skip to content

Latest commit

 

History

History
72 lines (50 loc) · 1.28 KB

README.md

File metadata and controls

72 lines (50 loc) · 1.28 KB

Java Getters and Setters

Example Application: Getters and Setters

Variables

Create a class and declare any variable:

public class Person {
	private String name;
	private String familyName;
	private int age;
}

Getters

Class person declares getters.

public String getName() {
	return name;
}
	
public String getFamilyName() {
	return familyName;
}
	
public int getAge() {
	return age;
}

It is possible to create a custom getter.

public String getFullName() {
	return name + " " + familyName;
}

Setters

Class person declares setters.

public void setName(String name) {
	this.name = name;
}

public void setAge(int age) {
	this.age = age;
}

public void setFamilyName(String familyName) {
	this.familyName = familyName;
}

Some links for more in depth learning