Multiple Inheritance
Explore multiple inheritance in C# by learning how interfaces enable a class to inherit from multiple sources. Understand how to implement this concept through a real-world example using a beverage and energy drink hierarchy, and compare interfaces with abstract classes to grasp their distinct roles in object-oriented design.
We'll cover the following...
What Is Multiple Inheritance?
When a class is derived from more than a single base class, i.e., when a class has more than one immediate parent, it is an instance of multiple Inheritance. Let’s take an example of Redbull:
RedBull is an energy drink as well as a beverage.
How to Implement?
As mentioned earlier, in C#, a class can’t extend from more than one classes. So the question arises, “How can we implement multiple inheritance?”
The answer to the above question is an Interface. In C#, multiple inheritance can ...