Method Overriding

noun

say it: “METH-ud oh-ver-RY-ding” /ˈmɛθəd ˌoʊvərˈraɪdɪŋ/

A subclass replacing a method it inherited with its own version of it.

What is Method Overriding?

Method overriding is when a child class replaces a method it inherited with its own version. Every Animal can Speak(), but a Dog overrides it to say "Woof".

public class Animal
{
    public virtual string Speak() => "...";
}

public class Dog : Animal
{
    public override string Speak() => "Woof";
}

In a sentence

  • “The e-bike's $15 rate comes from method overriding: it replaces the bike's price.”

Level: Apprentice · More OOP terms at this level

Updated

In other subjects