Assert from SCJP book:

In OO, the concept of IS-A is based on class inheritance or interface implementation.

IS-A: Expressed using keywords extends and implements. So if you extend some class or are using interface implementation you are expressing IS-A relationship.

For example: “Subaru extends Car —> Car extends Vehicle —> Vehicle (superclass)”

In this example we can say that Subaru IS-A Car and Car IS-A Vehicle.

HAS-A: This relationship is not expressed by any keyword as compared to IS-A relationship, instead this relationships are based on usage. It is basically expressed with the use of object of other class.

For example: If there’s no relationship between Vehicle class and Subaru class, we can use methods of Vehicle by calling on Vehicle’s object declared in Subaru class.

Advertisements