Exp 11
Exp 11
Hybrid inheritance in object-oriented programming refers to a scenario where a class is derived from two or
more base classes, employing multiple types of inheritance within the same program. For instance, let's consider
classes A, B, and C. Class A may serve as the base class for both B and C, representing a common set of
attributes and behaviours. Meanwhile, class B and class C might provide specific functionalities related to
different aspects of the program.
Algorithm –
1.) Define a base class "Base" with a display method.
2.) Create classes "Derived1" and "Derived2" inheriting from "Base," each with a display method.
3.) Create "Derived3" inheriting from both "Derived1" and "Derived2."
4.) In the main function, create a "Derived3" object.
5.) Demonstrate hybrid inheritance by calling display methods from different classes.
Code –
Output –
Discussion –
Hybrid inheritance allows for a flexible and comprehensive design. It enables the creation of complex class
relationships by combining various forms of inheritance, ensuring that classes can inherit properties and
methods from multiple sources. This approach enhances code reusability and fosters an organized and modular
programming structure, especially in situations where diverse attributes and behaviors need to be integrated into
a single class.
Finding/Learning –
What is Inheritance? What is Reusability? How is reusability implemented using inheritance? What is hydrid
inheritance?