It’s an in-line conditional. It works much like if (…) else
. The code before the ?
is the condition (is stepCounter
less than 0.5?), the code after is what to do if the condition is true, and the code after the :
is what to do if the condition is false.
The last part is more difficult to answer. As a guideline, if you aren’t sure, add the super call.
The only time you shouldn’t include the super call is if you explicitly don’t want to perform the parent functionality. For example, assume you had a Dog
class that had a speak()
function which played a sound. If you made a RabidDog
class extending Dog
, it should froth when it speaks, but it should also make a sound, so you only write code to froth, then call super.speak()
to play the sound as written in Dog
. If you made a DeadDog
class extending Dog
, it shouldn’t make any sound at all. You’d override speak()
to do nothing, making sure to not call super.speak()
.
And, @jacobalbano beat me to some shit. I guess that’s what I get for using my phone!
Edit: It’s creepy that we both wrote pretty much the same thing. Samsies!