I have a StepCounter class which extends Counter. Counter has an increment method which adds 1 to the counter. I need override this method so that increment method in the StepCounter class will increment the counter by the value of "step" e.g. if step=2 then the increment would add 2 to the counter instead of 1. Somehow I can't make it work. This is the coding I've done:
public class StepCounter extends Counter {
//fields
private int step;
//constructors
public StepCounter() {
super();
step = 2;
}
public StepCounter(int count, int step) {
super(count);
this.step = step;
}
//methods
public void setStep(int step) {
this.step = step;
}
public int getStep() {
return step;
}
@Override
public void increment() {
super.getCount() += step;
}
}
I've already tried various styles like
super.getCount() += getStep();
etc...
BTW getCount() method returns count value from Counter class.