Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about OCJP7. IS-A HAS-A

 
Nick Widelec
Ranch Hand
Posts: 226
Eclipse IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

If I had a class named "Pickle" and another class, say, "MotherClass", what if I had an ArrayList<Pickle> as an instance variable of the "MotherClass"? Would it be safe to say that MotherClass HAS-A Pickle?

It's a case where it's the instance variable is not directly "Pickle p = new Pickle();" But it's mentioned indirectly, and considering that the ArrayList at instantiation time will not have "Pickles" but they are going to be added later on. I wonder if there is a HAS-A relationship or not.

Thanks in advance.

 
meeta gaur
Ranch Hand
Posts: 305
Notepad Tomcat Server Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would be great if you post complete question.You know question but we don't know.

There is nothing like safe and unsafe has-a relationship.If a class have an object of another class then there is has-a relationship.
 
Nick Widelec
Ranch Hand
Posts: 226
Eclipse IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
meeta gaur wrote:It would be great if you post complete question.You know question but we don't know.

There is nothing like safe and unsafe has-a relationship.If a class have an object of another class then there is has-a relationship.


Well, if it was not clear I'll code it over:



Would be wrong to say that MotherClass HAS-A Pickle? Or we ought to say that MotherClass has a HAS-A relationship with ArrayList?


 
meeta gaur
Ranch Hand
Posts: 305
Notepad Tomcat Server Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MotherClass have has-a relationship with Pickle as well as ArrayList.
 
Nick Widelec
Ranch Hand
Posts: 226
Eclipse IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
meeta gaur wrote:MotherClass have has-a relationship with Pickle as well as ArrayList.


So would it be safe to say that MotherClass has-a Pickle in terms of has-a relationship?

Can I have also other views other than meet gaur? Asking for more opinions as the topic might be a little subjective and at the exam there are questions testing this topics.
Thanks in advance.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic