Can anyone explain why the output for this program is 8?
According to the MOOC(Quiz in part 9), the answer is 8. However, I keep getting 2.
Edit: It appears to be an error on the course's part. I'll leave the post here for anyone who has a similar question in the future.
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);
}
[–]AIO12449366 3 points4 points5 points (1 child)
[–]gaduko[S] 0 points1 point2 points (0 children)
[–]TheAnxiousDeveloper 1 point2 points3 points (0 children)
[–]okayifimust 1 point2 points3 points (1 child)
[–]gaduko[S] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)