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

Call subclass method from a superclass method?

My app has a structure similar to this: class Father{ a(){ ... } b(){a();} } class Son extends Father{ a(){ ..... }} //override b() is not overrided. When I create an instance of Son and I call b(), Father's a() is called, but I would like it…
supergiox
  • 1,586
  • 7
  • 19
  • 27
3
votes
1 answer

Override Equals and GetHashCode in class with one field

I have a class: public abstract class AbstractDictionaryObject { public virtual int LangId { get; set; } public override bool Equals(object obj) { if (obj == null || obj.GetType() != GetType()) …
user348173
  • 8,818
  • 18
  • 66
  • 102
3
votes
0 answers

How to remove sensitive info from the default C# HttpClient logging

Scenario I call an external service using an access token, which needs to be provided as an query parameter called token. Logging output When doing a GET request from C#, I see this logging (the real token is replaced by eyJ0... in this…
Stef Heyenrath
  • 9,335
  • 12
  • 66
  • 121
3
votes
1 answer

Kotlin: How to call super implementation of an extension method

In Kotlin I have code like the following: open class A { protected open fun B.doSomething() {} } class B {} class C : A() { override fun B.doSomething() { print("first, do some C-specific logic") print("now try to call…
3
votes
1 answer

I dont need to use atributes override and virtual when I change code of a method of the same name in a inherited class. Why is that?

Im trying to learn Csharp on my own. I read that if I want to change the code of the method textmethod in inherited class Class2, I have to write override in front of the method in Class2 and virtual in front of the method in base Class1. So I…
Magicco
  • 31
  • 2
3
votes
0 answers

Nestjs: overrideGuardguard in test file is not working

I am new to nestjs and to jest as well. I am trying to override a guard, but it's not working. So my folder structure is: "src/app.module.ts", "src/modules/auth/guards/myfile-guard.ts",…
Paresh
  • 31
  • 2
3
votes
3 answers

Implementing an interface with additional parameters in a method

I have a class MyClass that implements the interface IResp. public interface IResp { Response onResp(String a, String b) throws Throwable; } public class MyClass implements IResp { public onResp(String a, String b, String c)…
curiousCat
  • 157
  • 3
  • 11
3
votes
1 answer

How to override a function signature from a external library in TypeScript?

Is is it possible to override a function signature of a external package with your own types? Let's say I have a external package called translationpackage and I want to use the translate function of it. The package defines the function as…
icalvin102
  • 117
  • 8
3
votes
1 answer

Is an overridden pure virtual function, virtual?

Below you will see 3 classes. My question is why can I use override on the getArea() of the FunnySquare Class, even though it is not tagged as virtual in the Square Class. My assumption is that an overridden pure virtual function is virtual even…
Max Dolensky
  • 107
  • 7
3
votes
2 answers

Kotlin: "abstract member cannot be accessed directly" when using delegation ("by" keyword)

This is the sample code: class PurchaseHistory: MutableList by mutableListOf() { override fun add(element: PurchaseInfo): Boolean { // ... some code return super.add(element) } } However, I am getting abstract…
Amin Guermazi
  • 1,632
  • 9
  • 19
3
votes
1 answer

How to inherit and modify "Name" in Sale Order lines - Odoo14

My goal is to make the "Description" (name) field located in sale.order.line in order to show the products "Sales Description"(description_sale)....and NOT the products "Name"+"Sales Description" as per default. I've seen someone said i have to…
Gabin
  • 61
  • 8
3
votes
0 answers

how to access with single shared_ptr to vector of shared_ptr element

i need to call the overidden function inside B class through C class but it gives "Base" as a output rather than "Derived". when I call this code part classC.getTargetB().example(); i need to get "Derived" as a output. how can i reach my goal in the…
wdafoe666
  • 109
  • 9
3
votes
2 answers

Use reflection to find all public virtual methods and provide an override

I have a project where I want to be able to iterate across an instance of a class and find all methods that are marked public virtual. Then I want to override the instance of the class so that when the method is called I can call a different set of…
user852436
  • 31
  • 1
  • 3
3
votes
2 answers

Unable to override PHP class / function

I am unable to override a function in a child class at my local Ubuntu test LAMP server, but the very same code is resulting in the desired override when uploaded to a webserver. Original class: class HandsetDetection { function…
David Oliver
  • 2,424
  • 1
  • 24
  • 37
3
votes
3 answers

Overriding a "compiled statement" in python

For the sake of argument, let us say that I wanted to create my own module with a name like math (which is already pre-defined) and then import it from another module. Here is the directory structure of my code: __init__.py math.py So in the…
demongolem
  • 9,474
  • 36
  • 90
  • 105
1 2 3
99
100