• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

has -a relation ship

 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I know its a silly topic to post but i am little bit confused with has -a relationship. Can any one help me on this topic and explain me with examples.
Thanks in advance.
Divya
[ July 06, 2007: Message edited by: Divya Gehlot ]
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Divya,

Perhaps you may see something like following in the exam:

1- Film and Actor (IS-A relationship) : false
2- Car and Tires (Has-A relationship) : true
3- Bike and Honda (IS-A relationship) : true
etc.


Employee HAS-A Car.


Thanks,
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Divya,

Has- a relationship comes when you have an instance of one class as a member of another class. Lets Say, you have two classes A and B and you have an instance of B as a member of class A. In that case, class A is said to follow "has-a" relationship with class B.

A live example, a Bathroom class has an instance of Tub class as its member. In such case, "A Bathroom has a tub." Other example would be, "A ClassRoom has a BlackBoard" - where the ClassRoom class is having an instance of BlackBoard class as its instance member.

Whereas, "is-a" relationship speaks its deriving from one other. "An Employee is a Person will hold good but NOT an Employee has a Person". In this case, An employee extends a Person. In other words, An employee is a subclass of a Person class.

Hope this helps.
 
Divya Gehlot
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
First of all thanks for clearing my doubt. what I understood is if we create any refrence variable of a class and implementing in some class then it will be a has a relationship . correct???
Correct me if i am wrong
 
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OOP is all about mapping real-world objects and establishing relationships among them. We do it by identifying classes and IS-A, HAS-A relationships.
More often has-a relationship defines composition of the object.

1. An Animal has legs.
2. An Animal has tail.
3. An Animal has ears.

so,

[ July 06, 2007: Message edited by: Akhilesh Trivedi ]
 
Akhilesh Trivedi
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

What I understood is if we create any refrence variable of a class and implementing in some class then it will be a has a relationship



You are right. But its the other way round, if you have a HAS-A relationship between two classes, only then you will put the reference of one class into another, as a member of that class.
 
Divya Gehlot
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks I got it
 
Never trust an airline that limits their passengers to one carry on iguana. Put this tiny ad in your shoe:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic