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

Multilevel Inheritance

Definition:

In this type of inheritance, a derived class is created from another derived class.



Example:


   // C++ program to implement
  // Multilevel Inheritance
  #include <iostream>
  using namespace std;

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

  // first sub_class derived from class vehicle
  class fourWheeler : public Vehicle {
    public:
	   fourWheeler()
	{
		cout << "Objects with 4 wheels are vehicles\n";
	}
  };
  // sub class derived from the derived base class fourWheeler
  class Car : public fourWheeler {
    public:
	   Car() { cout << "Car has 4 Wheels\n"; }
  };

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

    

Output