# Inheritance in C#

Inheritance lets one class build on another, so shared code lives in one place. You will spot repeated code, generalize it into a base class, and specialize it in derived classes with constructors and overridden methods.

Updated: November 3, 2026

## [DRY Code in C#](https://www.ask-codey.com/courses/csharp-full-stack-bootcamp/topics/dry-code-in-csharp)

1. [DRY Code in C#](https://www.ask-codey.com/lessons/dry-code-in-csharp) (Novice): When several classes repeat the same properties and methods, the code breaks the DRY rule (Don't Repeat Yourself). One class that does everything isn't the answer either.

## [Introduction to Inheritance in C#](https://www.ask-codey.com/courses/csharp-full-stack-bootcamp/topics/introduction-to-inheritance-in-csharp)

1. [Introduction to Inheritance in C#: an overview](https://www.ask-codey.com/lessons/introduction-to-inheritance-in-csharp-an-overview) (Apprentice): Inheritance lets one class build on another. An archer is a character, so Archer inherits everything Character has, and adds what only archers have.
2. [Generalization vs Specialization](https://www.ask-codey.com/lessons/introduction-to-inheritance-in-csharp-generalization-vs-specialization) (Apprentice): Generalization moves what similar classes share into a base class; specialization keeps what makes each one different in its derived class.
3. [Inheritance in C#](https://www.ask-codey.com/lessons/introduction-to-inheritance-in-csharp-inheritance-in-csharp) (Apprentice): A derived class names its base class after a colon. It inherits every member of the base class, but its code can use only the public and protected ones, never the private ones; and every class inherits from object in the end.
4. [Inheritance and Constructors](https://www.ask-codey.com/lessons/introduction-to-inheritance-in-csharp-inheritance-and-constructors) (Journeyman): When a base class has a constructor with parameters, every derived class must call it with base(...). The base class's constructor always runs first.
5. [Overriding Methods](https://www.ask-codey.com/lessons/introduction-to-inheritance-in-csharp-overriding-methods) (Journeyman): A base class marks a method virtual so derived classes may change it; a derived class replaces it with override, and can still run the base version with base.MethodName().

## [Exercise: Inheritance](https://www.ask-codey.com/courses/csharp-full-stack-bootcamp/topics/exercise-inheritance)

1. [Exercise: Inheritance](https://www.ask-codey.com/lessons/exercise-inheritance) (Apprentice): Finish a café menu's Drink and Pastry classes so they inherit from MenuItem, with constructors that call base(...), an overridden Price and an overridden ToString().

Source: https://www.ask-codey.com/courses/csharp-full-stack-bootcamp/chapters/inheritance-in-csharp
