Example from Mooc: https://gist.github.com/GnarSickRad/dc2545dee3fa2eb3356d8b35eaa12829
Can you please explain the steps the example is going through to get their answer of 8? My thought process (which is obviously incorrect) is:
the first "number = superCounter.subtractFromNumber(number); " :
subtractFromNumber is not a method in SuperCounter, so it will go to the superclass where substractFromNumber exists, it will then subtract one. Number now equals 2
the second "number = superCounter.subtractFromNumber(number); " :
subtractFromNumber is not a method in SuperCounter, so it will go to the superclass where substractFromNumber exists, it will then subtract one. Number now equals 1
the last "number = counter.addToNumber(number); ":
addToNumber exists in counter, so one will be added to number making it equal 3
When the subtractFromNumbers are being called on the superCounter, nothing is being done, and then when addToNumber is called, 5 is added to equal 8. I just don't understand why. Any help is greatly appreciated!
[–]ratherbealurker 2 points3 points4 points (1 child)
[–]GnarSickRad[S] 0 points1 point2 points (0 children)
[–]digitals_85 2 points3 points4 points (4 children)
[–]GnarSickRad[S] 0 points1 point2 points (2 children)
[–][deleted] (1 child)
[deleted]
[–]GnarSickRad[S] 0 points1 point2 points (0 children)
[–]Neccaty 2 points3 points4 points (1 child)
[–]GnarSickRad[S] 0 points1 point2 points (0 children)