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
3 answers

Java unclear result

I define three classes (A,B,C): public class A { int i = 5; public A() { foo(); } public void foo() { System.out.println(i); } } class B extends A { int i = 6; } class C extends B { int i = 7; …
taypen
  • 33
  • 3
3
votes
3 answers

In C#, is it ok to virtualize every method?

This may make a lot of C# programmers cringe, but is it ok to virtual-ize every method in a base class -- even if certain methods are never overridden? The reason I need to do this is that I have a special case where I need to get C# to act like…
Sam Washburn
  • 1,817
  • 3
  • 25
  • 43
3
votes
1 answer

How to ensure that inheriting classes are implementing a friend function (ostream)?

I'd rather implement a non-friend function and directly mark the function as virtual. But I'm in a situation where I'd like to ensure that a specific set of classes implement an overloading of friend std::ostream& operator << (std::ostream& os,…
Greg
  • 579
  • 5
  • 26
3
votes
1 answer

Magento: Add Tab to Admin Order Details Page

I have created a custom Magento module which extends the core sales order functionality with some custom user input. After an order has been placed I would like to display this data in a custom tab on the order detail page of the admin area. I have…
Zac Seth
  • 2,742
  • 5
  • 37
  • 56
3
votes
1 answer

Accessing a hidden field in a subclass

According to the following quote, I expect to see overriden nullstackoverflow instead of overriden nullnull. What point did I miss? Hiding Fields Within a class, a field that has the same name as a field in the superclass hides the superclass's…
3
votes
3 answers

Basic CSS overriding the overflow: hidden; property

I have the following CSS class loading across all of my site: html, body { // no scrollbars before iframe resize overflow: hidden; } How do I override this, so that overflow is visible on a specific html page?
JZ.
  • 21,147
  • 32
  • 115
  • 192
3
votes
4 answers

Is it possible to override a default PHP function?

I would like to override the _() PHP function so that it supports one or more arguments. Is it possible to do that using PHP code?
laurent
  • 88,262
  • 77
  • 290
  • 428
3
votes
2 answers

CheckStyle - JavaDoc for overrided methods

For overrided methods Eclipse generate javadoc like this: /* (non-Javadoc) * @see com.ncube.qtpokertest.listeners.PlayerChangeListener# * nameChanged(com.ncube.qtpokertest.events.PlayerChangeEvent) */ it's not a javadoc comment, actually, but it…
Lampapos
  • 1,063
  • 1
  • 12
  • 26
3
votes
0 answers

Merge two XML files into one with Powershell

I am trying to merge 2 XML files with common nodes using Powershell for example: File1:
user1
  • 86
  • 5
3
votes
6 answers

override equals method to compare more than one field in java

What is the best way to override equals method in java to compare more than one field? For example, I have 4 objects in the class, o1, o2, o3, o4 and I want compare all of them with the passed object to the equals method. if (o1 != null && o2 !=…
K''
  • 5,020
  • 7
  • 33
  • 43
3
votes
1 answer

Multiple override-methods in inheritance each have multiple possible implementations

Let me introduce the following three classes: AbstractProcessor and these two child classes. The code below is not complex because there are only two child classes, but what if procedures1 and procedure2 both has many N candidate implementation? In…
orematasaburo
  • 1,207
  • 10
  • 20
3
votes
1 answer

How does the compiler decide between overloading and overriding?

class A { public void doSomething(float f) { //print "in A" } } class B extends A { public void doSomething(int i) { // print "in B" } public static void main(String[] args) { A a = new B(); …
3
votes
1 answer

Override type-hint of a parameter in __init__

On this code: class Obj(): def a(self): pass class ObjChild(Obj): def b(self): pass class A: def __init__(self, obj: Obj): self.obj = obj class B(A): def __init__(self, obj: ObjChild): …
omer mazig
  • 965
  • 2
  • 10
  • 17
3
votes
3 answers

Chrome local overrides with port number?

I'm trying to use Chrome local overrides (running on Windows) to override a javascript file. This works great for a URL where the port number is not specified: blah.com/static/js/main.js can be overridden with
Tom Grundy
  • 736
  • 5
  • 26
3
votes
1 answer

Overriding spaceship operator when parent class does not define spaceship operator for itself

The following code is treated differently by the compilers: #include struct A; struct I { virtual std::strong_ordering operator <=>(const A&) const { return std::strong_ordering::equal; } }; struct A : I { virtual…
Fedor
  • 17,146
  • 13
  • 40
  • 131