Inheritance in C#
Introduction
In this lesson, you will learn inheritance in C# for beginners. Inheritance allows one class to reuse properties and methods of another class.
What is Inheritance?
Inheritance is a feature of OOP where one class (child class) inherits from another class (parent class).
Basic Example
class Animal
{
public void Eat()
{
Console.WriteLine("Animal is eating");
}
}
class Dog : Animal
{
}
class Program
{
static void Main()
{
Dog d = new Dog();
d.Eat();
}
}
Types of Inheritance in C#
Single Inheritance
One class inherits from one parent class.
Multilevel Inheritance
A class inherits from a class which is already inherited.
Hierarchical Inheritance
Multiple classes inherit from one parent class.
Benefits of Inheritance
- Code reuse
- Reduces duplication
- Improves maintainability
Real-World Example
- Animal → Dog, Cat
- Vehicle → Car, Bike
Key Points
- Inheritance promotes code reuse
- Child class can access parent class methods
- Improves code structure
Internal Links
- Course Page: .NET Course for Beginners



