Single inheritance in C++-Types of inheritance

The inheritance

Types of inheritance

There are the following types of inheritance.

  1. Single inheritance
  2. Multiple inheritance
  3. Multilevel inheritance
  4. Hierarchical inheritance
  5. Hybrid inheritance
  6. Multi-path inheritance

In this blog post, you will learn single inheritance.

The type of inheritance in which there is a single base class and a single derived class is called single inheritance

I repeat-: single base class and single derived class…

Leave this syntax, if this confuses you.

Syntax:

Class derived:(visiblility mode)base

{

//body

}

Now, we are going to write a program for single inheritance.

We need one base class.

As well as one derived class..

And we are going to access the base class members from derived class…..using this method

  1. Inside both fxns of derived class, we will call the base class functions as base::fxn name();
  2. In the main function, we make a object of derived class

{

This method was also called as accessing the overridden members of a base class with the members functions of a base class.

}

Source code:

 

Output-:

enter the name of an employee

sam

enter the salary of an employee

44560

enter the title of a manager

ceo

name=

sam

salary=

44560

title of manager=

ceo

 

Be the first to comment

Leave a Reply

Your email address will not be published.


*