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 -shree
Anonymous
Ranch Hand
Joined: Nov 22, 2008
Posts: 18944
posted
0
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). Regards, Beno�t
SHALINI PATEL
Ranch Hand
Joined: Oct 31, 2000
Posts: 41
posted
0
Benoit is right.. Has a relationship denotes aggregation and is a relationship denotes inheritance. Hope this helps.
greg clarke
Greenhorn
Joined: Oct 06, 2000
Posts: 25
posted
0
shree 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]http://suned.sun.com/USA/certification/progsqwa.html[/ur] The answer given there is D and E.
Paul Anilprem
Enthuware Software Support
Ranch Hand