Different Types of Inheritance
Inheritance is a fundamental process in object-oriented programming that involves creating a new class, known as the Derived Class, based on an existing class, referred to as the Base Class. It offers numerous advantages, with code reusability being a prominent benefit. Instead of starting from scratch, developers can use the work of others by building upon existing classes, incorporating only the required new features.
This practice of reusing existing classes significantly reduces development time and effort, promoting efficiency and productivity. By capitalizing on the reusable code, developers can focus on implementing specific functionalities, thereby enhancing the overall quality and maintainability of the software solution. The reusability aspect of inheritance supports collaboration, code sharing, and promotes best practices within the programming community.
However, inheritance may be implemented in different combinations in Object-Oriented Programming languages as illustrated in figure and they include:
- Single Inheritance
- Multi Level Inheritance
- Hierarchical Inheritance
- Hybrid Inheritance
- Multipath inheritance
- Multiple Inheritance
Single Inheritance
When a Derived Class to inherit properties and behaviour from a single Base Class , it is called as single inheritance.
Multi Level Inheritance
A derived class is created from another derived class is called Multi Level Inheritance .
Hierarchical Inheritance
More than one derived classes are created from a single base class, is called Hierarchical Inheritance .
Hybrid Inheritance
Any combination of above three inheritance (single, hierarchical and multi level) is called as hybrid inheritance .
Multipath inheritance
Multiple inheritance is a method of inheritance in which one derived class can inherit properties of base class in different paths. This inheritance is not supported in .NET Languages such as C#.
Multiple Inheritance
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
Different types of inheritance in C#
- Single Inheritance
- Multilevel Inheritance
- Hierarchical Inheritance
- Multiple Inheritance (Through Interface)
- Hybrid Inheritance (Through Interface)
Multiple inheritance and Hybrid Inheritance are not supported in C# through class.
Different types of inheritance in c++
In C++ programming language , inheritance is a process in which one object acquires all the properties and behaviours of its parent object automatically. It allows user to create a Child Class (Derived Class) from an existing Parent Class (Base Class). To inherit from a class, C++ use the : symbol. C++ supports five types of inheritance:
- Single Inheritance
- Multiple Inheritance
- Multilevel Inheritance
- Hierarchical Inheritance
- Hybrid Inheritance
Different types of inheritance in Java
Object-Oriented Programming or better known as OOPs is one of the major pillars of Java that has utilized its power and ease of usage. The extends keyword indicates that you are making a new class that derives from an existing class. The meaning of "extends" is to increase the functionality. Java supports five types of inheritance:
- Single Inheritance
- Multilevel Inheritance
- Hierarchical Inheritance
- Multiple Inheritance (Through Interface)
- Hybrid Inheritance (Through Interface)
Multiple inheritance and Hybrid Inheritance are not supported in Java through class.
Different types of inheritance in Python
Python Inheritance allows you to define a class that inherits all the methods and properties from another class. Like C++, a class can be derived from more than one base classes in Python. This is called multiple inheritance. Python supports five types of inheritance:
- Single Inheritance
- Multiple Inheritance
- Multilevel Inheritance
- Hierarchical Inheritance
- Hybrid Inheritance
Conclusion
Inheritance in object-oriented programming facilitates code reusability, time efficiency, code organization, and extensibility. It allows developers to utilize existing code, build upon it, and tailor it to meet specific requirements, resulting in more efficient development processes and higher quality software.
- What is object-oriented programming?
- What is a Class?
- What is an Object?
- Constructors and Destructors
- What Is 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
- SOLID Principles in C#
- Solid Principles | Advantages and Disadvantages