LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-04-2011, 06:00 PM   #1
puppymagic
Member
 
Registered: Mar 2010
Distribution: Slackware
Posts: 66

Rep: Reputation: 4
Unhappy what does it mean to override the method of a superclass?


Let's say I have a method called mymethod()

and this method overrides the method of the super class method.

What does it mean to override a method?

does that mean mymethod() ignores everything that is in the method of the super class?

or does that means mymethod() also includes everything in the superclass method?

and when overriding a method, can I only override the methods of the same name, or I can override methods of any name?

thanks, experts @ linux questions!!
 
Old 10-04-2011, 06:23 PM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by puppymagic View Post
Let's say I have a method called mymethod()

and this method overrides the method of the super class method.

What does it mean to override a method?

does that mean mymethod() ignores everything that is in the method of the super class?

or does that means mymethod() also includes everything in the superclass method?

and when overriding a method, can I only override the methods of the same name, or I can override methods of any name?

thanks, experts @ linux questions!!
http://en.wikipedia.org/wiki/Method_overriding - you know, web search still works for me, and this was the very first match in Yahoo.
 
Old 10-04-2011, 06:23 PM   #3
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,657
Blog Entries: 4

Rep: Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938Reputation: 3938
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...)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Method Not Allowed: The requested method POST is not allowed for the URL /writedhcp.p WiWa Linux - Networking 15 01-06-2011 01:20 PM
[SOLVED] [Perl] OOP Accessor Method for Array Attributes and Append Method brianmcgee Programming 1 10-18-2010 11:05 AM
calling a superclass constructor kpachopoulos Programming 1 09-04-2006 12:15 PM
SlackWare :Method Not Allowed The requested method POST is not allowed for the URL slack31337 Linux - Software 0 04-08-2006 06:09 PM
override defines alaios Programming 1 09-14-2005 10:40 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration