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
146
votes
14 answers

What is the difference between dynamic and static polymorphism in Java?

Can anyone provide a simple example that explains the difference between Dynamic and Static polymorphism in Java?
Prabhakar Manthena
  • 2,223
  • 3
  • 16
  • 30
145
votes
8 answers

Override and reset CSS style: auto or none don't work

I would like to override following CSS styling defined for all tables: table { font-size: 12px; width: 100%; min-width: 400px; display:inline-table; } I have specific table with class called 'other'. Finally…
sergionni
  • 13,290
  • 42
  • 132
  • 189
140
votes
16 answers

How to underline a UILabel in swift?

How to underline a UILabel in Swift? I searched the Objective-C ones but couldn't quite get them to work in Swift.
Esqarrouth
  • 38,543
  • 21
  • 161
  • 168
139
votes
14 answers

Calling method using JavaScript prototype

Is it possible to call the base method from a prototype method in JavaScript if it's been overridden? MyClass = function(name){ this.name = name; this.do = function() { //do somthing } }; MyClass.prototype.do = function() { …
Mark Clancy
  • 7,831
  • 8
  • 43
  • 49
137
votes
11 answers

What is function overloading and overriding in php?

In PHP, what do you mean by function overloading and function overriding. and what is the difference between both of them? couldn't figure out what is the difference between them.
Parag
  • 4,754
  • 9
  • 33
  • 50
136
votes
11 answers

How to override equals method in Java

I am trying to override equals method in Java. I have a class People which basically has 2 data fields name and age. Now I want to override equals method so that I can check between 2 People objects. My code is as follows public boolean…
user702026
133
votes
5 answers

Python Method overriding, does signature matter?

Lets say I have class Super(): def method1(): pass class Sub(Super): def method1(param1, param2, param3): stuff Is this correct? Will calls to method1 always go to the sub class? My plan is to have 2 sub classes each override method1…
asdasasdsa
  • 1,331
  • 2
  • 9
  • 3
130
votes
4 answers

Calling a base class's classmethod in Python

Consider the following code: class Base(object): @classmethod def do(cls, a): print cls, a class Derived(Base): @classmethod def do(cls, a): print 'In derived!' # Base.do(cls, a) -- can't pass `cls` …
Sridhar Ratnakumar
  • 81,433
  • 63
  • 146
  • 187
123
votes
3 answers

Overriding non-virtual methods

Let's assume this scenario in Visual C++ 2010: #include #include using namespace std; class Base { public: int b; void Display() { cout<<"Base: Non-virtual display."<
Leif Lazar
  • 1,386
  • 2
  • 11
  • 12
122
votes
6 answers

How to override the properties of a CSS class to avoid copying and renaming styles

I am fairly new to CSS3 and I want to be able to do the following: When I add a class into a an element, it overrides the properties of another class used in this specific element. Let's say that I have
user3075049
  • 1,331
  • 3
  • 11
  • 14
122
votes
2 answers

Overriding class constants vs properties

I would like to better understand why, in the scenario below, there is a difference in the way class constants are inherited vs. instance variables.
Tom Auger
  • 19,421
  • 22
  • 81
  • 104
120
votes
7 answers

When NOT to call super() method when overriding?

When I make my own Android custom class, I extend its native class. Then when I want to override the base method, I always call super() method, just like I always do in onCreate, onStop, etc. And I thought this is it, as from the very beginning…
sandalone
  • 41,141
  • 63
  • 222
  • 338
116
votes
10 answers

Modify HTTP responses from a Chrome extension

Is it possible to create a Chrome extension that modifies HTTP response bodies? I have looked in the Chrome Extension APIs, but I haven't found anything to do this.
captain dragon
  • 1,289
  • 2
  • 9
  • 8
113
votes
10 answers

Is it possible to override a non-virtual method?

Is there any way to override a non-virtual method? or something that gives similar results (other than creating a new method to call the desired method)? I would like to override a method from Microsoft.Xna.Framework.Graphics.GraphicsDevice with…
zfedoran
  • 2,986
  • 4
  • 22
  • 25
112
votes
13 answers

Java: Calling a super method which calls an overridden method

public class SuperClass { public void method1() { System.out.println("superclass method1"); this.method2(); } public void method2() { System.out.println("superclass method2"); } } public class…
jsonfry
  • 2,067
  • 2
  • 15
  • 16