HOME C C++ PYTHON JAVA HTML CSS JAVASCRIPT BOOTSTRAP JQUERY REACT PHP SQL AJAX JSON DATA SCIENCE AI

Multiple Inheritance

Definition:

Multiple Inheritance is a feature of C++ where a class can inherit from more than one class. i.e one subclass is inherited from more than one base class.



Example:


    // C++ program to explain
    // multiple inheritance
    #include <iostream>
    using namespace std;

    // first base class
    class Vehicle {
      public:
	    Vehicle() { cout << "This is a Vehicle\n"; }
   };

   // second base class
   class FourWheeler {
       public:
	     FourWheeler()
	{
		cout << "This is a 4 wheeler Vehicle\n";
	}
  };

  // sub class derived from two base classes
  class Car : public Vehicle, public FourWheeler {
 };

  // main function
  int main()
  {
	// Creating object of sub class will
	// invoke the constructor of base classes.
	Car obj;
	return 0;
  }
    

Output