Questions tagged [overriding]

Method overriding, in object oriented programming, is a language feature that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its superclasses or parent classes.

Method overriding, in object oriented programming, is a language feature that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its super classes or parent classes.

The implementation in the subclass overrides (replaces) the implementation in the superclass by providing a method that has same name, same parameters or signature, and same return type as the method in the parent class.

Don't confuse it with

Read on Wikipedia

Example in Java

class Thought {
    public void message() {
        System.out.println("I feel like I am diagonally parked in a parallel universe.");
    }
}

public class Advice extends Thought {
    @Override  // @Override annotation in Java 5 is optional but helpful.
    public void message() {
        System.out.println("Warning: Dates in calendar are closer than they appear.");
    }
}
8096 questions
3
votes
1 answer

Overriding of Dictionary.KeyCollection

I am trying to inherit from Dictionary, but my problem is, that when the Dictionary.Keys are being queried, I want to override them. (that is, the KeyCollection) of the dictionary. How can that be solved? thanks
Himberjack
  • 5,682
  • 18
  • 71
  • 115
3
votes
4 answers

Is it possible to have specialized parameters in overridden methods?

Let's say I have an abstract parent class called "shape", and that there are multiple subclasses (triangle, square, circle... ). I want to define an abstract method in the parent "shape" class which all subclasses must implement, let's call it…
user85116
  • 4,422
  • 7
  • 35
  • 33
3
votes
1 answer

Culture in a Silverlight application

I'm developing a Silverlight application which is translated to multiple languages. It's a business application, and people from many different countries use it. The strings in the user interface of the application will be dependant on what…
Nitramk
  • 1,542
  • 6
  • 25
  • 42
3
votes
1 answer

Rails Association Extensions: Override a HABTM assignment (collection=) method

In a question I've previously answered, I used an association extension to override a HABTM collection's append (<<) method (Also, a similar question): has_and_belongs_to_many(:countries) do def <<(country) if [*country].all? {|c|…
GeReV
  • 3,195
  • 7
  • 32
  • 44
3
votes
2 answers

Implementing Custom Membership user and Custom Membership Provider

References http://msdn.microsoft.com/en-us/library/6tc47t75%28v=VS.80%29.aspx http://msdn.microsoft.com/en-us/library/ms366730.aspx Question In the 2nd link precisely under heading Create a Custom Membership Provider you will note that they mention…
3
votes
1 answer

Is it possible to override global variable in target-specific one in make?

Consider the following makefile: # various settings, lots of them # (supposed to be in defaults.mk) option1="glob_val1" option2="glob_val2" #option3="glob_val3" # uncomment and it will override target-specific in sub-make option4="glob_val4" # goal…
VLH
  • 43
  • 4
3
votes
3 answers

Extend magento core controller (Checkout/OnepageController)

I am having problems while overriding a core controller. I want to add a new function but it only works if I do it in the core file (code/core/checkout/controllers/onepagecontroller.php). I have followed some post, but it's not working. Some of them…
saturno
  • 43
  • 1
  • 6
3
votes
1 answer

Cannot override startElement method

My class extends DefaultHandler. It overrided 3 methods startDocument, EndDocument, EndElement successfully, but when i override StartElement, Eclipse show this error The method startElement(String, String, String, Attributes) of type…
Wayne
  • 6,361
  • 10
  • 46
  • 69
3
votes
3 answers

Calling overridden method in generic subclass in C#

I'm having problems with my own implementation of generic linked list. Assignment that I'm working on says that two subclasses NodeElementLong and NodeElementString must descend from base class NodeElement. In NodeElement there should be a virtual…
Expertness
  • 33
  • 3
3
votes
1 answer

AS3 - extend a function?

I have an Entity class with a destroy() function. I also have an Enemy class that extends Entity, and I want to add some lines to the destroy() function. Is there a way to extend functions in ActionScript 3, or is copy and paste the way to go?…
apscience
  • 7,033
  • 11
  • 55
  • 89
3
votes
2 answers

C++ override function of object created by subclass

I was wondering if it's possible to override just one function in a class without creating an entirely new class. I would like bObj1.foo(); to output "foo!" and bObj2.foo() to output "foo?", but currently they both output "foo!". #include…
Jeremiah
  • 512
  • 2
  • 5
  • 17
3
votes
0 answers

Multiple inheritance and virtual function name ambiguity (not a diamond problem!)

How is this even allowed to compile and run? Since BaseA and BaseB have pure virtual functions, each should be overridden in Derived in order to be able to instantiate the class. Does this mean that the foo() override implements both? Is there any…
galinette
  • 8,896
  • 2
  • 36
  • 87
3
votes
1 answer

Can concrete functions from a derived class override virtual functions from a separate base class?

Is it possible to have concrete functions from a derived class override virtual functions from a separate base class? Like this: // abstract Person class I_Person { public: virtual int age() = 0; virtual int height() = 0; }; // concrete…
comp1201
  • 407
  • 3
  • 13
3
votes
1 answer

Is it safe to override Free method?

Is it safe to override Free method? I'm asking because I would like to use something like this. I know it's very ugly to use TerminateThread, but in my case it's very critical to kill the process with all its threads immediately. I've seen the…
TLama
  • 141
  • 6
3
votes
3 answers

How to override a JQuery unobtrusive method without modifying jquery.validate.unobtrusive.min.js?

I want to override the onErrors method in jquery.validate.unobtrusive.js to display error messages as hyper links to the html elements. However, I don't want to change the method in jquery.validate.unobtrusive.js since this file gets updated as…
Bob
  • 785
  • 1
  • 11
  • 18