Multiple Inheritance - heshawacooray/OOP-Heshawa GitHub Wiki

Definition: Multiple inheritance is an OOP feature where a class can inherit properties and behaviors from more than one base class. In C++, a class can inherit from multiple classes, combining their functionality.

Example code:

#include <iostream>
using namespace std;

class Animal {
public:
    void eat() {
        cout << "Eating food" << endl;
    }
};

class Mammal {
public:
    void breathe() {
        cout << "Breathing air" << endl;
    }
};

class Dog : public Animal, public Mammal {
public:
    void bark() {
        cout << "Barking" << endl;
    }
};

int main() {
    Dog d;
    d.eat();     // Inherited from Animal class
    d.breathe(); // Inherited from Mammal class
    d.bark();    // Defined in Dog class

    return 0;
}
⚠️ **GitHub.com Fallback** ⚠️