wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question about OCJP7. IS-A HAS-A Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question about OCJP7. IS-A HAS-A" Watch "Question about OCJP7. IS-A HAS-A" New topic
Author

Question about OCJP7. IS-A HAS-A

Nick Widelec
Ranch Hand

Joined: Feb 28, 2013
Posts: 226

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.


OCAJP 7, OCPJP 7
meeta gaur
Ranch Hand

Joined: Dec 05, 2012
Posts: 305

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.


My one regret in life is that I am not someone else.
- Woody Allen
Nick Widelec
Ranch Hand

Joined: Feb 28, 2013
Posts: 226

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

Joined: Dec 05, 2012
Posts: 305

MotherClass have has-a relationship with Pickle as well as ArrayList.
Nick Widelec
Ranch Hand

Joined: Feb 28, 2013
Posts: 226

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.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question about OCJP7. IS-A HAS-A