Multiple Inheritance

Multiple Inheritance is a feature of object-oriented concept where a class can inherit from more than one classes. In simple terms, if a child class having multiple parent then that is known as Multiple Inheritance. In c++ Multiple Inheritance is possible. Lets discuss this furthur with code examples.

CODE

EG 1 . Creating 2 classes called Rectangle and Car. Inheriting both to a new class called sampleClass

class Rectangle {
  public:
    double length, width;
    double Area() {
        return length * width;
    }
}

class Car {
  public:
    int totalNumberofPassangers;
    string color;
    void Drive() {
        cout << "Start Driving" << endl;
    }
}

//sampleClass can now access all the fields and methods of both Rectangle and Car.
class sampleClass : Rectangle, Car {

}