What Is Inheritance ?
Inheritance is a fundamental feature of an Object-Oriented programming. It is the process of creating a new Class, called the Derived Class, from the existing class, called the Base Class. Inheritance is a very elegant way to reuse and modify the data and functionality that has already been defined in the Base Class, also you can add new data and functionality to the Derived Class. Since the Derived Class inherits all properties of the Base Class, the Derived Class has a larger set of properties than the Base Class. However, the Derived Class may override some or all the properties of the Base Class.
Inheritance and the .NET Framework
The Inheritance has many advantages, the most important of them being the reusability of code. Rather than developing new Objects from scratch, new code can be based on the work of other developers, adding only the new features that are needed. The reuse of existing classes saves time and effort. When you create a class to derive from another class, the inherited class implicitly gains all the data and functionality of the base class, except for its constructors and destructors.
From the above example, Cars and Trucks have certain common properties; all have engine, wheels, horns etc. Thus they can be grouped under a Class called Vehicles. Apart from sharing these common features, each Derived Class has its own particular features - Cars use petrol while Trucks use diesel.
Multiple inheritance in .Net Framework
Multiple inheritances allows programmers to create classes that combine aspects of multiple classes and their corresponding hierarchies. In .Net Framework, the classes are only allowed to inherit from a single parent class, which is called single inheritance. More about.... Why in .NET multiple inheritance is not allowed
However, inheritance may be implemented in different combinations in Object-Oriented Programming languages as illustrated in figure and they include:
More about.... Different Types of Inheritance
- What is a Class?
- What is an Object?
- Constructors and Destructors
- What are the different types of inheritance ?
- What are Access Modifiers ?
- Why Classes cannot be declared as Protected?
- Can we declare private class in namespace
- Difference between Classes and Structures
- Can we use pointers in C# ?
- Why abstract class can't create instance
- Can you prevent your class from being inherited
- Difference between method Overloading and Overriding
- Difference between Early Binding and Late binding
- What is nested class
- What is partial class ?
- What is Virtual Method
- Difference between class and object
- What is Data Encapsulation?
- Object Based Language and OOPs