I have a super class 'BuildingMaterial' and loads of subclasses, i.e. Stone, Wood, Clay, etc. All subclasses behave similarly: 1 int field that stores the amount of a building material in units. They can be constructed parameterless or with an int. I already know that ALL subclasses of BuildingMaterial will have these two constructors, how do I avoid coding them into every single class? Here's an example of what I don't want to do in every class:
public final class Stone extends BuildingMaterial {
private int amount;
//constructors
public Stone() {
amount = 0;
}
public Stone(int i) {
amount = i;
}
//methods
public int getAmount() {
return amount;
}
}