March 05, 2015

Which Man class properly represents the relationship "Man has a best friend who is a Dog"?

Given :

A. class Man extends Dog { }
B. class Man implements Dog { }
C. class Man { private BestFriend dog; }
D. class Man { private Dog bestFriend; }
E. class Man { private Dog<bestFriend>; }
F. class Man { private BestFriend<dog>; }









Answer: D

Explanation:

If the Class has entity reference then it is called Aggregation.Aggregation is also known for "HAS - A" relationship.
In the above question we have "Man has a best friend " which represents container-ship or "HAS-A" relationship . Therefore bestFriend is one of the Member of Man .

"Who is a Dog".This part may confuses us ,but in the question it is very much clear in stating that best friend is of type Dog . So Datatype is Dog and variable name is bestFriend .


Since we have Dog bestFriend as a data member of Man ,therefore Man has to be a Class which has this data member which satisfies "HAS-A" relationship.

Option D.


Related Topics

0 comments:

Post a Comment