Image

C++ - Inheritance - 1. Single Inheritance

1. Single Inheritance

A class inherits its property to another class then such type of inheritance known as single inheritance.

In the above diagram class B is derived class A. Therefore object of class B can access the public property of derived class B as well as its own.

e.g: Program for single level inheritance
#include<conio.h>
#include<iostream.h>
class Employee{
     protected:
	int eno;
     public:
	    Employee()
	    {
	     cout<<"\nEnter Emp No ";
	     cin>>eno;
	    }

};
class Manager:public Employee{
 public:
	void showgrade(){
	 cout<<"\n Employee no : "<<eno;
	 cout<<"\n Grade : n";

	}

};

void main()
{
 Manager m;
 clrscr();
 m.showgrade();
 getch();
}
O/P
Employee no : 101
Grade :n