write a program to implement multiple inheritance in c++ ?
- In C++ inheritance can be described as a process of creating new classes from existing classes.
- New classes inherit some of the properties and behaviour of the existing classes.An existing class that is "parent" of a new class is called a base class. New class that inherits properties of the base class is called a derived class.
- Using this inheritance technique we can reuse code .
- It also provides possibility to extend existing classes by creating derived classes.
class DerivedClass : accessSpecifier BaseClass
- In this syntax an access specifier can be public, protected and private. The default access specifier is private.
- Access specifiers affect accessibility of data members of base class from the derived class.
- In addition, it determines the accessibility of data members of base class outside the derived class.
Types Of Inheritance :
There are different types of inheritance:
- Single Inheritance
- Multiple Inheritance
- Multilevel Inheritance
- Hierarchical Inheritance
- Hybrid (Virtual) Inheritance
Multiple Inheritance :
- Multiple inheritance enables a derived class to inherit members from more than one parent.
- That Deriving directly from more than one class is usually called multiple inheritance.
Class DerivedClass: accessSpecifier BaseClass1, BaseClass2, …, BaseClassN
class child1 //Derived Class1
void geta() // Get the input value of "a"
cout<<"Enter the a value :";
class child2 // Derived Class2
void getb() // Get the input value of "b"
cout<<"\nEnter the b value:";
class parent:public child1,public child2 // Call the drived class
void display() // Display the sum value
c=(a + b);
cout<<"\nsum : "<<c; }
parent p; // object creation