Hello, again. Still working through the Javanotes text by Eck. I am in Chapter 9 now.
A few chapters ago, I came across this sentence, and made a flash card out of it.
The major use of super is to override a method with a new method that extends the behavior of the inherited method, instead of replacing that behavior entirely. (bold his)
Despite believing I understand "super", I have a terrible time with this flash card, and I don't think I'm understanding what he's trying to get across.
When I see "The major use of super is..." I always say "to gain access to methods in the superclass." (I know it can also be used to access constructors and hidden fields, but I'm going for the major use.)
Is that what he's saying, too, and I am just having a hard time parsing his grammar? Or do I have a fundamental misunderstanding of the major use of super? I have read what the Java Language Specification has to say about super, as well as the tutorials on the Oracle website, but didn't find those to be any help.
your understanding is correct. for example, say you are overriding a method in subclass . now when you call the method , it just print/process what *it has* .
some time you need to call the same version of super class method either begining or end of you override method(subclass method.) so how do you call?
implicitly it will be like this
so you have to explicitly call the method with immediate super class reference
for instance, see how to override Object#finalize .
I read "major use" as "main use" or "primary use" -- what he's saying there is that if you don't use super, then you're essentially replacing the functionality of the parent class method with the new code in the subclass method. When you use super, you are extending the original behavior with the subclass code that gets executed after the call to super.