Skip to content

fefong/java_GettersAndSetters

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

Releases

No releases published

Packages

No packages published

Languages