Difference Between Inheritance and Containership

Inheritance:

The inheritance allows us to define sub-classes that inherit all the variables and methods from their super-classes. The old or existing class is called the base class and the new class is known as the derived class.

Containership:

It allows any class to access the members of another class by making it the object of that class. Containership is also known as Composition.

Inheritance vs Containership:

InheritanceContainership
1. It enables a class to inherit data and functions from a base class1. It enables a class to contain objects of different classes as its data member.
2. The derived class may override the functionality of base class.2. The container class can't override the functionality of the contained class.
3. The derived class may add data or functions to the base class.3. The container class can't add anything to the contained class.
4. Inheritance represents a "is-a" relationship.4. Containership represents a "has-a" relationship.