Created
September 18, 2021 23:37
-
-
Save evrentan/57981b5bddbf125fb4b46a91f2d3cb9a to your computer and use it in GitHub Desktop.
Java Encapsulation Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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