Types of Inheritance
Different types of Inheritances are:
- Single Inheritance
- Multiple Inheritance
- Multilevel Inheritance
- Hierarchical Inheritance
- Hybrid Inheritance
Single Inheritance
A derivative class with only one base class is referred to as single or simple inheritance.

Example:
Class A { int a; public: int b; void getab() { a=5; b=6; } int geta() { return a; } void showab { cout<<"a= "<<a<<"b= "<<b; } }; class B: public A { int c; public: void sumab() { c= b*geta(); } void showc() { cout<<"c= "<<c<<endl; } } ;
Multiple Inheritance
A class may inherit attributes from two or more classes as set out below figure is called Multiple Inheritance. It allows us to combine characteristics from multiple existing classes to define new classes. It is like a child who inherits the physical characteristics of the father and the intellect of the mother.

Example:
Class A { public: int a; // other members if any }; Class B { public: int b; // other members if any }; Class C { public: int c; // other members if any }; Class X: public A, public B, public C { private: int c; public: int sumofanc() { return a+b+c; } };
Multilevel Inheritance
In this type of inheritance, the derived class inherits one class, who in turn inherits another class. The Superclass for one is a subclass for the other.

Class B is called an intermediate base class because it provides a link for inheritance between A and C, the ABC chain is known as the inheritance path.
Example:
class A { protected: int a; public: A() { a=5; } }; class B: public A { protected: int b; public: B() { b=15; } }; class C: public B { private: int c; public: C() { c=a+b; } void display() { cout<<"c="<<c<<endl;}; };
Hierarchical Inheritance
In this inheritance, it is possible to build a subclass by inheriting the properties of the base class. A subclass can be used as a basis for lower-level classes and so forth. One or more sub-classes derived from only one base class at each level.

Example:
class A { //content of base class - A }; class B: public A { //content of derived class - B }; class C: public A { //content of derived class - C }; class D: public A { //content of derived class - D };
Hybrid Inheritance
The inheritance hierarchy which reflects any legal combination of the other four types of inheritance is referred to as Hybrid Inheritance.

Example:
Class A { // Members of the class - A }; Class B: public A { Members of class - B }; Class C: public A { // Members of class -C }; Class D: public B, public C { // Members of class - D };
Example program
class Student { protected: int rollno; char name[20]; public: Student() { rollno=0; strcpy(name,NULL); } Student(int a, char *t) : rollno(a) { strcpy(name,t); } // { rollno=a;strcpy(name,t); } void getdata() { cout<<"Enter roll no. and name: "; cin>>rollno>>name; } void displaydata() { cout<<"Roll Number = "<<rollno<<endl; cout<<"Student Name= "<<name<<endl; } }; class Test: public virtual Student { protected: float sub1, sub2; public: void getmarks() { cout <<"Enter two subjects marks out of 100: "; cin>>sub1>>sub2; } void displaymarks() { cout<<"Marks in sub1 max. 100="<<sub1<<endl; cout<<"Marks in sub2 max. 100="<<sub2<<endl; } }; class Sports : public virtual Student { protected: int score; public: void getscore() { cout<<"Enter sports score out of 10 : "; cin>>score; } void displayscore() { cout<<"Score in Sports max.10 = "<<score<<endl; } }; class Result : public Test, public Sports { private: float total; float avg; char result[10]; public: void display() { total = sub1+sub2; avg = total/2.0; if ((sub1>=40) && (sub2>=40)) strcpy(result,"Pass"); else strcpy(result,"Fail"); cout<<"Total Marks = "<<total<<endl; cout<<"Average Marks = "<<avg<<endl; cout<<"Result = "<<result<<endl; } };