If two classes are related with one another there can be two kinds of relationship between them.
- kind of relationship
- has a relationship
kind of relationship is supported by inheritance.
has a relationship is supported by composition or containership.
In Inheritance if a class Y is derived from Class X,we can say that "Class Y is a kind of Class X". This is because class Y has all the characteristics of X, and in addition some of its own.
For this reason inheritance is often called a kind of relationship.
In has a relationship you simply create objects of your existing class inside the new class.
void setdata(char t,float c,char *m)
void setdata(char *m,char *d)
carburettor c; //embedded object
C++ has much more sophisticated mechanisms for code reuse in the form of composition and inheritance.
Composition is useful when classes act like a data type.