Coupon Accepted Successfully!


Single Inheritance

When only one class is derived from a single base class, such a derivation of a class is known as single inheritance; further, the derived class is not used as a base class. This type of inheritance uses one base and one derived class.
The new class is termed derived class, and the old class is called base class, as shown in Figure: Single inheritance. A derived class inherits data member variables and functions of the base class. However, constructors and destructors of the base class are not inherited in the derived class.

Fig. Single inheritance


The newly created class receives entire characteristics from its base class. In single inheritance, there are only one base class and one derived class. The single inheritance is not as complicated as compared with other types of inheritance. Consider the following example:
In the above diagram, class ABC is a base class, and class abc is a derived class. The arrow shows that class abc is derived from class ABC. The program given below illustrates the single inheritance.

11.6 Write a program to show single inheritance between two classes.


Enter Name and Age : Santosh 24
Enter Height and Weight : 4.5 50
Name : Santosh
Age : 24 Years
Height : 4.5 Feets
Weight : 50 Kg.
Explanation: In the above program, the two classes ABC and abc are declared. The class ABC has two protected data members, name and age. The class abc has two float data members, height and weight with a two-member function getdata() andshow(). The class abc is derived from class ABC. The statement class abc: public ABC defines the derived class abc. In function main(), x is an object of the derived class abc. The object x invokes the member function getdata() and show(). This function reads and displays data, respectively.

Test Your Skills Now!
Take a Quiz now
Reviewer Name