Skip to content

Instantly share code, notes, and snippets.

@evrentan
Created September 18, 2021 23:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evrentan/57981b5bddbf125fb4b46a91f2d3cb9a to your computer and use it in GitHub Desktop.
Save evrentan/57981b5bddbf125fb4b46a91f2d3cb9a to your computer and use it in GitHub Desktop.
Java Encapsulation Example
public class Animal {
//declare variables private
private String name;
private String breed;
private Integer age;
//declare public getter & setter methods
public String getName() {
return name;
}
public void setName(String newName) {
this.name = newName;
}
public String getBreed() {
return breed;
}
public void setBreed(String newBreed) {
this.breed = newBreed;
}
public Integer getAge() {
return age;
}
public void setAge(Integer newAge) {
this.age = newAge;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment