C# Tutorial: Inheritance
Base classes, derived classes, virtual/override methods, abstract classes, and sealed.
Inheritance
Inheritance lets one class extend another, reusing its fields and methods while adding or changing behaviour.
C# supports single inheritance (one base class) but multiple interface implementation.
What you'll learn in this C# inheritance tutorial
This interactive C# tutorial has 8 hands-on exercises. Estimated time: 20 minutes.
- Basic inheritance — Use `: BaseClass` to inherit.
- virtual and override — `virtual` marks a base method as overridable. `override` replaces it in the derived class.
- base keyword — `base` calls the base class constructor or method.
- Abstract classes — `abstract` methods have no implementation — subclasses must provide one.
- sealed keyword — `sealed` prevents further inheritance. `sealed override` prevents further overriding.
- is and as operators — `is` checks the type. `as` casts to a type (returns null on failure instead of throwing).
- Polymorphic collections — A `List<Animal>` can hold any Animal subclass.
- Object as universal base class — Every C# class implicitly inherits from `object` (System.Object).
C# Inheritance concepts covered
- Inheritance