Types of Inheritance
Types of Inheritance
Lecture
Types of Inheritance
Types of Inheritance
• Single Inheritance
• Multiple Inheritance
• Multilevel Inheritance
• Hybrid Inheritance
• Hierarchical Inheritance
• Multipath Inheritance
Single Inheritance
Class A
Class B
Inheritance (example)
Class A
Class B
Class C
Multilevel Inheritance
class Grand_Parent {
class Child : public Parent {
public: public:
void MyGrandParent() void Me()
{ {
cout << "Grand Parent class" << endl; cout << "Child class" << endl;
} }
}; };
Class A Class B
Class C
Multiple Inheritance (example)
Class A
Class B Class C
Class D
Inheritance (example)
class C
class A
{
{
public:
public:
int y;
int x; int main()
C() {
}; {
y = 4;
} D obj1;
class B : public A obj1.sum();
};
{ return 0;
class D : public B, public C
public: }
{
B()
public:
{
void sum()
x = 10;
{
}
cout << "Sum= " << x + y;
};
}
};
Other types of Inheritance