JAVA : Read IS-A and HAS-A relationship concept


In OO, the concept of IS-A is based on class inheritance or interface
implementation. IS-A is a way of saying, “this thing is a type of that thing.” For
example, a Mustang is a type of horse, so in OO terms we can say, “Mustang IS-A
Horse.” Subaru IS-A Car. Broccoli IS-A Vegetable (not a very fun one, but it still
counts). You express the IS-A relationship in Java through the keywords extends
(for class inheritance) and implements (for interface implementation).

public class Car {
public class Subaru extends Car {


HAS-A relationships are based on usage, rather than inheritance. In other words,
class A HAS-A B if code in class A has a reference to an instance of class B. For
example, you can say the following,
A Horse IS-A Animal. A Horse HAS-A Halter.

The code might look like this:

public class Animal { }

public class Horse extends Animal {

    private Halter myHalter;


About rajkirpal

i am a software engineer. and i have decent knowledge about java technologies like ANDROID, Servlet, Jsp, Struts, Hibernet, Spring, J2ME, Java Script, Ajax, JQuery, CSS. Further i am Preparing Easy understandable materials/documents upon the same java technologies and developing project in core java , advanced java and j2me , ANDROID as per the requirements Also designing the web sites and logos Thank You.
This entry was posted in J2SE. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s