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

How to avoid excessive code duplication when using enums in Java

I am refactoring some legacy code and have come across a problem which I'm sure has a elegant solution - but I can't quite get there. Initially there were a load of classes which extended an abstract class BaseType. Each of these classes has a enum…
Martyn
  • 16,432
  • 24
  • 71
  • 104
3
votes
1 answer

How to locally extend Base operator in Julia (in module)

I don't know how to locally extend a Base operator and I couldn't find anything about that. I can obviously redefine it in the global scope (REPL or module) doing : import Base.- -(x, y::Nothing) = nothing -(x::Nothing, y) = nothing But I would…
jejouch
  • 31
  • 3
3
votes
1 answer

How to override PrestShop 1.7.7 module classes?

I want to override class MySQL of PrestaShop module ps_facetedsearch that is located in file: mystore/modules/ps_facetedsearch/src/Adapter/MySQL.php How do I achieve this? EDIT: Class MySQL that I want to override is defined in file…
Marek J.
  • 310
  • 2
  • 18
3
votes
0 answers

Why my compiler doesn't allow overriding a deleted non-throwing virtual member function as a deleted throwing member function?

I've read from C++ primer 5th ed. That a virtual member function that won't throw (noexcept) must be overriden as non-throwing function. The exception is if the virtual member function is defined as a 'deleted' member. So I've tried this: struct…
Maestro
  • 2,512
  • 9
  • 24
3
votes
1 answer

How to enforce mandatory parent method call when calling child method?

What I want is to enforce that when a child class inherits from a parent and that it overrides the parent method without explicitly calling it, an error is raised. The errror could be raised at initialization of the bad class or when calling the…
Oily
  • 538
  • 3
  • 11
3
votes
1 answer

Unit testing overridden methods which call super()

I'm trying to figure out the best way of writing a unit test for an overridden method which calls super() as the last step. Basically, I want to massage parameters before they're used in the base class. Here's an example of a method: @Override …
Ickster
  • 2,167
  • 4
  • 22
  • 43
3
votes
2 answers

Why does Collections.UnmodifiableMap.UnmodifiableEntrySet override the stream() method?

While looking at the source code, I could see that the stream() method has been overridden in Collections.UnmodifiableMap.UnmodifiableEntrySet. But the code seems to be identical to Collection.stream() except the return type in…
Gautham M
  • 4,816
  • 3
  • 15
  • 37
3
votes
3 answers

Objective C - Reflection and overriding methods?

I am trying to use reflection to override the getter method for my properties and create lazy initialization. how can I do that? // This should be a public method maybe a category to NSObject - (void)overrideGetterMethod { //somehow convert my…
aryaxt
  • 76,198
  • 92
  • 293
  • 442
3
votes
4 answers

A C++ covariance/overriding/circularity problem

I am writing a backend of a compiler of a subset of Java. The backend writes C++ code. There is some hypothetical Java code, though, that I do not known how to translate to C++. An example problem is shown in the following code. A is extended by B,…
arataj
  • 373
  • 3
  • 12
3
votes
0 answers

io.micrometer @Timed not emitting metrics for @Override method in Java and Springboot App. Tried registering TimedAspect manually

I am trying to capture the metrics for an override method in Java / Springboot. Below is the snippet @Override @Timed(value = "processor_timer", histogram = true) public void preProcess(byte[] key, byte[] event, Headers headers) { …
Gupta
  • 31
  • 2
3
votes
1 answer

Wordpress - woocommerce: change "SKU" string inside single-product meta.php

I'm simply trying to change the string "SKU" to show something else inside the single-product meta.php file. I'm using a child theme. The parent theme got a woocommerce.php file in the path /inc/compat/. Because of this, as far as I understood, I…
Andrea
  • 31
  • 2
3
votes
2 answers

Is it possible to override the nested class definition of an abstract parent, within an inheriting class?

Context I have an scenario in which I wish to define several Bar classes, each of which must define Request, Response and Error classes of their own. For this reason, I have written an abstract Foo class, within an intension to force an the…
George Kerwood
  • 1,248
  • 8
  • 19
3
votes
3 answers

react material-ui how to override muibox-root

I want to override the MuiBox-root style for the whole application.According to the official documentation I need to identify the class: And among other things I can override it: But if I proceed this way, it just removes the styling. What am I…
assembler
  • 3,098
  • 12
  • 43
  • 84
3
votes
2 answers

how to override System.out.println(map)

I would like to override System.out.println(map) to print not  {A=1, B=2, C=3,...} but  A 1 B 2 C 3 …
hjy
  • 31
  • 2
3
votes
3 answers

Visual Studio & SubVersion : What about Machine Specific Files

As an example we have a Unit Test Project with an app.config file. The app.config file is configured to work on our build server. But if we want to run our tests locally (with local database) we have to change the app.config...everytime... is there…
Lieven Cardoen
  • 25,140
  • 52
  • 153
  • 244
1 2 3
99
100