Inheritance
noun
say it: “in-HAIR-ih-tuns” /ɪnˈhɛrɪtəns/
Making a new class from an existing one, so it gets everything the parent has and changes only what differs.
What is Inheritance?
Inheritance lets one class build on another. The new class gets all the data and methods of the existing class and can add or change some. A Cat class can inherit from Animal and add a Purr method.
public class Animal
{
public string Name { get; set; }
public void Eat() => Console.WriteLine( quot;{Name} is eating");
}
public class Cat : Animal
{
public void Purr() => Console.WriteLine("Purrr");
}
In a sentence
- “Through inheritance, the e-bike got the bike's bell without a line of its own.”
Level: Apprentice · More OOP terms at this level
Updated