Skip to content

Instantly share code, notes, and snippets.

@orderr66
Last active January 10, 2021 12:40
Show Gist options
  • Save orderr66/a16b7863e9a3d28762553eaaf5db31cf to your computer and use it in GitHub Desktop.
Save orderr66/a16b7863e9a3d28762553eaaf5db31cf to your computer and use it in GitHub Desktop.
Example class for medium OOP post.
//name of class
public class Agent {
private String name;
private Integer heightInCM;
//default constructor
public Agent() {
this.name = "Smith";
this.heightInCM = 177;
}
//second constructor
public Agent(String name, Integer heightInCM) {
this.name = name;
this.heightInCM = heightInCM;
}
//accessor methods
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getHeightInCM() {
return heightInCM;
}
public void setHeightInCM(Integer heightInCM) {
this.heightInCM = heightInCM;
}
//public interface of class
public void fight() {
fightImplementation();
}
//private implementation of class
private void fightImplementation() {
//implementation of fight
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment