File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes 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 ""has a" "is a" relationships doubt " Watch ""has a" "is a" relationships doubt " New topic

"has a" "is a" relationships doubt

sri devij
Ranch Hand

Joined: Oct 23, 2000
Posts: 37
Which two demonstrate a "has a" relationship? (Choose two.)
A.public interface Person{ }public class Employee extends Person{ }
B.public interface Shape{ }public interface Rectangle extends Shape{ }
C.public interface Colorable{ }public class Shape implements Colorable{ }
D.public class Species{ }public class Animal{private Species species;}
E.interface Component{ }class Container implements Component{ private Component[] children;}
I guessed the ans for the above q is D&E.Is it right?Can anyone clear me about this
Thanx in advance
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi Sri,
The has-a relationship is an containing association, i.e. object containing other objects. For example and to take the example Q, a Animal has a species, or a GUI component has children.
An association is implemented in Java using an attribute. When the association is a one-to-one association (multiplicity = 1), the attibute is a single reference to the object. When there is a one-to-many relationship (multiplicity > 1), you must use an array or any collection.
It is opposed to a is-a relationship implemented in Java by subclassing (extends).
Ranch Hand

Joined: Oct 31, 2000
Posts: 41
Benoit is right..
Has a relationship denotes aggregation and
is a relationship denotes inheritance.
Hope this helps.
greg clarke

Joined: Oct 06, 2000
Posts: 25
This question puzzled me when I first saw it because I hadn't seen an explanation of "is a" versus "has a" quite so much in terms of sub-classing and implementing. The indication that exactly 2 options are correct was a help though.
It now makes more sense to me if I translate "extends" to "is a" and member variables to "has a". Implements is also (a weaker?) "is a".
So, perhaps simplistically, the following seems a reasonable translation:

    [A] An employee is a person.
    [B] A rectangle is a shape.
    [C] A shape is (a) colorable (thing). (Or: A shape is colorable.)
    [D] An animal is not a species, but an animal has or belongs to a species.
    [E] An AWT Container actually is a Component, but it has components.

    If, like me, you wondered where the answers are shown for the Sun sample questions, then take a look here:[url][/ur] The answer given there is D and E.
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3635
This post might help you...
Get Certified, Guaranteed!
(Now Revised for the new Pattern)

Enthuware - Best Mock Exams and Questions for Oracle Java Certifications
Quality Guaranteed - Pass or Full Refund!
I agree. Here's the link:
subject: "has a" "is a" relationships doubt
It's not a secret anymore!