The various forms of inheritance in C++ with necessary coding.
• Inheritance is a mechanism of deriving a new class from a old class.
• It provides the concept of reusability
• By inheritance some or all the properties of a class can be derived in to another class.
• The class which provides the properties is called as base class and the class which
derives the properties is called as derived class.
There are five types of inheritance viz
1. Single level inheritance
2. Multiple inheritance
3. Multilevel inheritance
4. Hybrid inheritance and
5. Hierarchical inheritance
It is a type of inheritance in which a class can inherit properties from more than one class.
Class derivedclass name : visibility mode baseclass1,visibilitmode baseclass2
body of the derived class;
visibility mode can be either private or public.
int a; public :
cout <<”\n enter the value for a\n”; cin >>a;
cout <<” \n enter the value for b \n”; cin>>b;
class dc : public bc1, public bc2
cout <<”The values of a and b are” ; cout <<<”\n”<
Enter the value for a 20
Enter the value for b 30
The values of a and b are 20 30