| Author |
has -a relation ship
|
Divya Gehlot
Ranch Hand
Joined: Sep 10, 2006
Posts: 238
|
|
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 ]
|
SCJP1.5(81%)<br />SCDJWS(94%)<br />next mission SCEA(but need to wait or that)
|
 |
Chandra Bhatt
Ranch Hand
Joined: Feb 28, 2007
Posts: 1707
|
|
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,
|
cmbhatt
|
 |
Raghavan Muthu
Ranch Hand
Joined: Apr 20, 2006
Posts: 3327
|
|
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.
|
Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
|
 |
Divya Gehlot
Ranch Hand
Joined: Sep 10, 2006
Posts: 238
|
|
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
|
 |
Akhilesh Trivedi
Ranch Hand
Joined: Jun 22, 2005
Posts: 1493
|
|
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 ]
|
Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
|
 |
Akhilesh Trivedi
Ranch Hand
Joined: Jun 22, 2005
Posts: 1493
|
|
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
Joined: Sep 10, 2006
Posts: 238
|
|
Hi, Thanks I got it
|
 |
 |
|
|
subject: has -a relation ship
|
|
|