File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes have a question about Has-A relationship Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "have a question about Has-A relationship " Watch "have a question about Has-A relationship " New topic
Author

have a question about Has-A relationship

chang Anne
Greenhorn

Joined: Jul 02, 2003
Posts: 29
I have a question about Has-A relationship (object).
for example,

Is the above example "a Has-A relationship"?
Thank you.
Miki Muzsi
Ranch Hand

Joined: Jun 23, 2003
Posts: 120
Yes, in this case Person has a shoe. And btw, for coding standards is prefered that the class starts with a capital .
And is-a relationship would be if for example you extend class Person (of Shoe)
e.g.
class Person {
Shoe shoe = new Shoe();
}
class Student extends Person {
...
}
In this case:
Student is-a Person
Person has-a Shoe
Student has-a Shoe (via inheritence!!!)
Hope it helps,
Miki


Miki<br /> <br />SCJP 1.4, SCBCD 1.3
chang Anne
Greenhorn

Joined: Jul 02, 2003
Posts: 29
Hello,
Thank you.
What's the benefit of using "Has-A" relationship?
Miki Muzsi
Ranch Hand

Joined: Jun 23, 2003
Posts: 120
Has-a and is-a relationship are used in object oriented programming. I would suggest to take a book on OOP or find something on the net. As a start you can have a look here.
Tha main idea is that is-a is used for inheritence, and has-a is used for composition. Both have their own strength; however many times has-a is prefered over is-a.
However for the exam you only need to know the basics and to recognize is-a and has-a constructs.
Good luck,
Miki
chang Anne
Greenhorn

Joined: Jul 02, 2003
Posts: 29
Hello Miki Muzsi,
Thank you for providing me the information.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: have a question about Has-A relationship
 
Similar Threads
a true or false statement
build a dynamic form with an arrayList
Weaknesses of a 2-tier architecture
preparing for SCJP 5
has a relationship