Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Example of an abstract class
- * An abstract class can have instance variables and methods of both static and normal nature
- * Can have a constructur, but that cannot be called directly, as abstract classes cannot be instantiated
- * It should contain one abstract method (which is just method signature, to be implemented later in child classes extending it
- *
- */
- public abstract class HealthAbstract {
- public HealthAbstract() {
- System.debug('Welcome to the abstract class of Health');
- }
- public Integer weight;
- //define a method to set current weight of different people (different classes in this example)
- public void setWeight(Integer wt) {
- weight = wt;
- }
- //define a method to get the weight from other classes
- public Integer getWeight() {
- if(weight != null) {
- return weight;
- } else {
- return null;
- }
- }
- //define an abstract method which needs to be implemented in all child classes extending this
- public abstract String workoutIntensity(Integer BicepsSize, Integer ChestSize);
- }
Add Comment
Please, Sign In to add comment