I’m currently learning the basics of Java with the MOOC Java Programming II. I’ve reached this quiz but I don’t understand why the program is supposed to print 8 instead of 2.
Could somebody please explain it to me?
public class Counter {
public int addToNumber(int number) {
return number + 1;
}
public int subtractFromNumber(int number) {
return number - 1;
}
}
----------------------
public class SuperCounter extends Counter {
@Override
public int addToNumber(int number) {
return number + 5;
}
}
----------------------
public static void main(String[] args) {
Counter counter = new Counter();
Counter superCounter = new SuperCounter();
int number = 3;
number = superCounter.subtractFromNumber(number);
number = superCounter.subtractFromNumber(number);
number = counter.addToNumber(number);
System.out.println(number);
}
New contributor
Roman Rehm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.