• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

has a relationship

 
parag bharambe
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3776
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This 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
 
parag bharambe
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul.
I understand is-a but can you elaborate on has-a relationship
parag
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Anuj Anand
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
so
class Car extends Vehicle
{
int wheels = 4
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic