Difference between Single and Multiple Inheritance in C++

Last Updated : 25 Jun, 2026

Single inheritance and multiple inheritance are two inheritance mechanisms in C++ that allow a class to acquire properties and behaviors from other classes. The main difference lies in the number of base classes from which a derived class inherits.

  • Single inheritance involves one base class and one derived class.
  • Multiple inheritance allows a derived class to inherit from two or more base classes.
  • Both improve code reuse but differ in complexity and design flexibility.

Single Inheritance

Single Inheritance is a type of inheritance in which a derived class inherits the properties and methods of a single base class. It allows code reuse and establishes a hierarchical relationship between classes.

  • One child class inherits from one parent class.
  • Enables code reuse and reduces code duplication.
singleinh

Syntax

class Derived : public Base {

// Class body

};

Example: Program to illustrate Single Inheritance

C++
#include <iostream>
using namespace std;
class A {
public:
    int k = 1000;
    float salary = 80000;
};
class B : public A {
public:
    float bonus = 8000;
    void ts()
    {
        cout << "Total salary.." << (salary + bonus)
             << endl;
    }
};
int main()
{
    B b1;
    cout << "Salary:" << b1.salary << endl;
    cout << "Bonus:" << b1.bonus << endl;
    b1.ts();
    return 0;
}

Output
Salary:80000
Bonus:8000
Total salary..88000

Explanation: Class B inherits the members of class A and can directly access them according to the inheritance access specifier.

Multiple Inheritance

Multiple Inheritance is a type of inheritance in which a derived class inherits properties and methods from more than one base class. C++ supports multiple inheritance directly, allowing a class to combine functionalities from multiple parent classes.

  • A single derived class can inherit from multiple base classes.
  • Helps reuse code and combine features from different classes into one class.
multiple-inheritance

Syntax

class Derived : public Base1, public Base2 {

// Class body

};

Example: Program to illustrate Multiple Inheritance

C++
#include <iostream>
using namespace std;
class A {
protected:
    int a;

public:
    void get_a(int n) { a = n; }
};

class B {
protected:
    int b;

public:
    void get_b(int n) { b = n; }
};

class C : public A, public B {
public:
    void display()
    {
        cout << "The value of a is : " << a << endl;
        cout << "The value of b is : " << b << endl;
        cout << "Product of a and b is : " << a * b;
    }
};

int main()
{
    C c;
    c.get_a(10);
    c.get_b(20);
    c.display();

    return 0;
}

Output
The value of a is : 10
The value of b is : 20
Product of a and b is : 200

Explanation: Class C inherits members from both classes A and B, allowing it to use functionality from both base classes.

Single Inheritance Vs Multiple Inheritance

FeatureSingle InheritanceMultiple Inheritance
DefinitionA derived class inherits from one base class.A derived class inherits from two or more base classes.
Code ReusabilityReuses functionality from a single parent class.Combines functionality from multiple parent classes.
ComplexitySimple to design, understand, and maintain.More complex because multiple parent classes are involved.
AmbiguityNo ambiguity in member access.Can cause ambiguity when multiple base classes contain members with the same name.
Diamond ProblemDoes not occur.May occur and is typically resolved using virtual inheritance.
Memory OverheadGenerally lower due to a single inheritance path.Can be higher because multiple base class subobjects may exist.
MaintainabilityEasier to debug and maintain.Harder to maintain in large class hierarchies.
Real-World ExampleAnimal → DogAmphibiousVehicle → LandVehicle + WaterVehicle
Language SupportSupported by most object-oriented languages.Supported in C++, but not directly supported in Java and C#.
Best Used WhenA class naturally extends a single parent class.A class needs features from multiple independent classes.

Related Article: Inheritance in C++

Comment