wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Has-A relationsship explanation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Has-A relationsship explanation" Watch "Has-A relationsship explanation" New topic
Author

Has-A relationsship explanation

ranjan sarkar
Greenhorn

Joined: Jun 30, 2008
Posts: 7
Q)Man has a best friend who is a Dog
How you can explain this with Has-A relation
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 452



Man has a bestFriend. hence man will have a bestfriend variable.
......who is a Dog. hence bestFriend is an instance of class Dog.

avi sinha


SCJP 5.0 SCWCD 5.0
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38493
    
  23
The Man-Dog example is called "association"; a Man does not cease to be a Man if the Dog dies.

The examples I have given are called "composition"; an Aeroplane without a Wing is no longer an aeroplane in the fullest sense of the word. And if you disagree, try taking the wings off your aeroplane at 29000 feet
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Has-A relationsship explanation