It's not a secret anymore!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes has a relationship 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 relationship" Watch "has a relationship" New topic

has a relationship

parag bharambe
Ranch Hand

Joined: Sep 01, 2000
Posts: 41
Hello friend
this is one more question form Sun exam
. Which two demonstrate a "has a" relationship? (Choose two.)
1) public interface Person{ }
public class Employee extends Person{ }
2) public interface Shape{ }
public interface Rectangle extends Shape{ }
3)public interface Colorable{ }
public class Shape implements Colorable{ }
4)public class Species{ }
public class Animal{private Species species;}
5)interface Component{ }
class Container implements Component{
private Component[] children;
Ans is 4,5.
I want to know more about has a relationship? and why the answer are correct?
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3556
This 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!
parag bharambe
Ranch Hand

Joined: Sep 01, 2000
Posts: 41
Thanks Paul.
I understand is-a but can you elaborate on has-a relationship
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
In the end, if something has-a whatever, there must be a place to keep that whatever. Therefore there must be a variable somewhere to keep the information for what it has.
In 4 the Animal has-a Species. The class has the information for the species and stores it in a variable of type Species. If it had read
public class Animal extends Species{}
then it would "be-a" Species.
In 5 it has-a Component array named children.

"JavaRanch, where the deer and the Certified play" - David O'Meara
Anuj Anand
Ranch Hand

Joined: Nov 18, 2000
Posts: 96
When a class extends another class use 'is' a relation..If we are talking about attributes of a class like variables ,methods of a classs .There is a 'has a' relation.
For e.g A car is a vehicle.
A car has 4 wheels
class Car extends Vehicle
int wheels = 4
I agree. Here's the link:
subject: has a relationship
It's not a secret anymore!