what does it mean to override the method of a superclass?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Generally speaking, the term "override" does, indeed, mean that you are superseding the default behavior by supplying behavior of your own.
Within your handler, you can, if you wish, invoke the behavior (if any...) of the superclass, thereby making it possible for you to define the behavior of your subclass in terms of "augmenting" or "selectively modifying" what (if anything...) the superclass would ordinarily do.
Specifically: your mymethod() would ordinarily supersede the entire behavior of the parent's mymethod(), but it does have the capability to, if it chooses, invoke "the parent's implementation of mymethod() if it has one." It can do that at any point in the execution of its own version of this routine ... or, of course, it can elect not to do so at all. (It doesn't have to know in advance just what that the effect, if any, of doing that might be. It simply has the capability to invoke the underlying functionality, if any, that it has overridden.)
So you can conceivably do things like this: if some_condition then "transport the user to the planet Xarxon," then (do what the superclass's method would normally do) then "feed the dog" else "set the world on fire." (Actual implementation of these small details is left as an exercise to the reader...)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.