0% found this document useful (0 votes)
6 views3 pages

Understanding Inheritance in OOP

Inheritance is a mechanism in object-oriented programming that allows a new class to inherit properties and behaviors from an existing class, promoting reusability. There are several types of inheritance, including single, multi-level, multiple, multipath, hierarchical, and hybrid inheritance, each defining different relationships between base and derived classes. For example, in single inheritance, Class B derives from Class A, while in multi-level inheritance, Class C derives from Class B, which in turn derives from Class A.

Uploaded by

kandelbibek999
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)
6 views3 pages

Understanding Inheritance in OOP

Inheritance is a mechanism in object-oriented programming that allows a new class to inherit properties and behaviors from an existing class, promoting reusability. There are several types of inheritance, including single, multi-level, multiple, multipath, hierarchical, and hybrid inheritance, each defining different relationships between base and derived classes. For example, in single inheritance, Class B derives from Class A, while in multi-level inheritance, Class C derives from Class B, which in turn derives from Class A.

Uploaded by

kandelbibek999
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

What is inheritance? Explain with an example.

Ans: Inheritance is a process of transferring or deriving properties of an


existing class to new class or classes. It is the process by which objects of one
class acquire the characteristics of object of another class. For example, all
vehicles in a class may share similar properties of having wheels and a
motor. In OOP, the concept of inheritance provides the idea of reusability.

The different types of inheritance are as follows:

 Single inheritance: In this inheritance, a derived class is created from a


single base class. For example:

Class A

Class B

Single inheritance

 Multi-level inheritance: A derived class is created from another


derived class and is called multi-level inheritance. For example:
Class A

Class B

Class C

Multi-level inheritance
 Multiple inheritance: In this inheritance, a derived class is created
from more than one base class.

Class A Class B

Class C

Multiple inheritance

 Multipath inheritance: In this inheritance, a derived class is created


from another derived classes and the same base class of another
derived classes.

Class A

Class C
Class B

Class D

Multipath inheritance
 Hierarchical inheritance: More than one derived class are created
from a single base class, is called Hierarchical inheritance.

Class A

Class B Class C

Class D Class E Class F Class G

Hierarchical Inheritance

 Hybrid Inheritance: Derived class is formed with the combination of


more than one types of inheritance is known as hybrid inheritance.

Class A
Class A

Class C Class B

Class D Class E Hybrid Inheritance

You might also like