| 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.
|
 |
 |
|
|
subject: have a question about Has-A relationship
|
|
|