disclaimer: I'm a very green greenhorn and am utterly subject to correction (and I welcome it) on all of this . . . .
I ran across this same Master Exam question yesterday. It suprised me as well. I figured it would compile and run since I wrongly assumed that
super would have the effect of standing in for the name of the immediate parent class.
I then got quite confused by the "correct answer explanation" from the Master Exam (which I now regard to be in error).
As S. Singh mentioned, the provided Explanation text states the following, "only instance methods can be overridden and calls to super only apply to overridden methods".
I find that the first clause of the explanation isn't especially relevant.
Then as Satya points out above, the second part "calls to super only apply to overridden methods" is at least confusing. In my tests, non-static method code can legally, successfully call
super.myMethod() even when no overriding happens, specifically when:
the calling method does not override anything in the super instancethe method of the parent object called is not overridden in the calling object
(Of course using
super absent any overriding is probably always unnecessarily redundant).
In fact, while my NetBeans
IDE shows a warning, a non-static method can even compile calling
super.myMethod() when
myMethod() is a static method in the superclass. It seems equivalent to calling the static method using ClassName.staticMethod() notation. Of course this makes sense I guess since you can call a static method through a reference to an instance from the same class.
The most helpful explanation of why the call won't compile came from Antonio who said:
So, if you call this or super from a static context, this doesn't work because this and super are linked to an instance of the class
Now, after chasing this down some, I would describe
super in this context as behaving somewhat like a reference for accessing the the current object as if ignoring any overidding members (whether they exist in fact or not) of the subclass of which the object is an instance.
I guess another way to say this is that
super seems to act like a reference (to the current object) that is typed as the object's immediate parent class and functioning as if dynamic method selection is disabled from stepping down into the overrides of the current object's lowest/actual type.
(Yuck. I'm sorry that I can't seem to find a simple way to express the above idea.)
But, as antonio points out, from a static method there is no way to reference the current instance, since the code runs apart from an instance of its class. Thus
super can't compute. The ClassName.staticMethod() notation has to be used.
To recap, the Master Exam gives us the correct answer,
I just think it is in error when it explains why, in the study guide material it offers.