Explain the is-a and has-a relationship between classes used in inheritance and in composition.
What will be an ideal response?
If the inheritance is properly done, an object of class D that is derived from class B will be an object of class B. One author puts this relationship as “is substitutable for”. If an object of class B can be used in a context, then any object of class D must be substitutable for the class B object. It would be wrong to derive a class car from class engine. A car is not an engine. We cannot substitute a car for an engine. On the other hand, if we make a class engine object a member of our class car, we say the car object has-a(n) engine. Moral: Take great care in building inheritance relationships.
You might also like to view...
A screenshot is an image of an active window on your computer that you can paste into a document
Indicate whether the statement is true or false
_______ elements are used for both input and output.
Fill in the blank(s) with the appropriate word(s).