• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

has a relationship

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Enthuware Software Support
Posts: 4679
51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Paul.
I understand is-a but can you elaborate on has-a relationship
parag
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
}
 
reply
    Bookmark Topic Watch Topic
  • New Topic