Last active
January 10, 2021 12:40
-
-
Save orderr66/a16b7863e9a3d28762553eaaf5db31cf to your computer and use it in GitHub Desktop.
Example class for medium OOP post.
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
//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