Inheritance in C++

Inheritance in C++:

C++, like all object-oriented languages, supports class inheritance. Inheritance may be defined as the capability of one class to inherit properties from an existing (base) class. The new class is referred to as the derived class or child class or subclass. The existing class is called the base class or parent class or superclass. The most important advantage of inheritance in C++ is code reusability. Without redefining the old class, you can add new properties to the derived class, and you even can redefine an inherited class member function.

Needs and Objective of Inheritance in C++:

The major needs and objectives of inheritance are:

(1) The capability to express the inheritance relationship which ensures the closeness with the real-world models.

(2) Inheritance extends the functionality of an existing class.

(3) Inheritance establishes “a kind of” relationship.

(4) Idea of reusability, i.e., the new class can use some of the features of the old class (base class).

(5) Transitive nature of inheritance, i.e., it can be passed on further

(6) The redundancy can be reduced by abstracting a superclass from new subclasses (known as a generalization).

Types of Inheritance in C++:

In C++, any class can be a base class. More than one class can be derived from a single base class and a derived can be a base class to another class or classes. Inheritance may take place in many forms which are described below:

(1) Single Inheritance- In single inheritance, a derived class inherits only from one base class.

Single Inheritance in C++

(2) Multiple Inheritance- In multiple inheritance, a derived class inherits from multiple base classes.

Multiple Inheritance IN C++

(3) Hierarchical Inheritance- In hierarchical inheritance, many derived classes inherit from a single base class.

Hierarchical Inheritance in C++

(5) Multilevel Inheritance- The transitive nature of inheritance is reflected by this form of inheritance. When a derived class inherits from a class that itself inherits from another class, it is known as multilevel inheritance.

Multilevel Inheritance in C++

(6) Hybrid Inheritance- When a derived class inherits from multiple base classes and all of its base classes inherit from a single base class, this form of inheritance is known as hybrid inheritance.

Hybrid Inheritance in C++

Object-Oriented Programming (OOP)
Computer Software and Hardware
Information and Communication Technology
C++ Data Types
Tokens in C++
Install MySQL on Windows
Inheritance (object-oriented programming)– Wikipedia

Comments (No)

Leave a Reply