0% found this document useful (0 votes)
8 views2 pages

Exp 11

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Uploaded by

8177.sk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Exp 11

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Uploaded by

8177.sk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Program – 11

Aim – Write a program to implement hybrid inheritance.


Description of aim and Related theory –
C++ strongly supports reusability through a concept called inheritance. Inheritance allows new classes to be
created by reusing properties of existing ones. In this mechanism, a new class, called the derived class or
subclass, can inherit traits from an old class, known as the base class. Derived classes can inherit properties
from multiple classes, either in a single level (single inheritance) or across several levels (multilevel
inheritance). The process of deriving one class from another derived class is called multilevel inheritance. This
approach enables programmers to create flexible and extensible programs by adapting existing classes to meet
specific requirements, fostering efficient code reuse.

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?

You might also like