This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes IS A and HAS  A   Relationship Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "IS A and HAS  A   Relationship" Watch "IS A and HAS  A   Relationship" New topic

IS A and HAS A Relationship

kiranb reddy

Joined: Sep 28, 2008
Posts: 20
Hi All,

Can anyone explain the exact difference between IS-A and HAS-A relationship with an example.

Please help me.

Thanks and Regards,
Thomas Thevis
Ranch Hand

Joined: Sep 02, 2008
Posts: 87
Hello Kiran,

try to use the search function of the forum first. You will come to threads like HAS-A relationship?.
If you don't find an answer to your question, come back afterwards.


SCJP 5.0, SCJD in progress
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

an apple IS A fruit.

an apple HAS A seed.

a Ford Mustang IS A car

a Ford Mustang HAS A windshield.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
John Eric

Joined: Nov 16, 2010
Posts: 1
consider this example:-

class A{

class B extends A{

the above code shows IS A relationship, this can be implemented as Inheritance.

Class Library{
Book b=new Book();
CD cc=new CD();

this shows HAS A relationship.
HAS A also know as composition.

Nitesh Nandwana
Ranch Hand

Joined: Jun 07, 2011
Posts: 115

Best artical on IS-A and HAS-A relationship
I agree. Here's the link:
subject: IS A and HAS A Relationship
It's not a secret anymore!