aspose file tools*
The moose likes Beginning Java and the fly likes Use of Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Use of "super"" Watch "Use of "super"" New topic
Author

Use of "super"

Ken Austin
Ranch Hand

Joined: Aug 20, 2012
Posts: 39

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.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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
i.e,


for instance, see how to override Object#finalize .

hope, you understand my point
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4456
    
    6

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.


Junilu - [How to Ask Questions] [How to Answer Questions]
Ken Austin
Ranch Hand

Joined: Aug 20, 2012
Posts: 39

Thanks, guys.

Junilu, I wish he had just said it your way. That would be easier to understand.

Seetharaman: Yes, I did. Thank you for the reassurance and the explanation.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Use of "super"