This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark ""has a" "is a" relationships doubt " Watch ""has a" "is a" relationships doubt " New topic
Author

"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
-shree
Anonymous
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).
Regards,
Beno�t
SHALINI PATEL
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
Greenhorn

Joined: Oct 06, 2000
Posts: 25
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

Joined: Sep 23, 2000
Posts: 3254
    
    2
This post might help you...
http://www.javaranch.com/ubb/Forum24/HTML/004960.html
-Paul.
------------------
Get Certified, Guaranteed!
(Now Revised for the new Pattern)
www.enthuware.com/jqplus


Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: "has a" "is a" relationships doubt
 
Similar Threads
Qn from Sun's samples
Sun qstns - "has a" relationship
Sun sample ques.
Help plz
has a relationship