• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Object Orientation

 
Ikechukwu Morah
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What type of relationship is represented by the code snippets below:
A. public class Species {}
public class Animal {
private Species species;
}
B. interface Component {}
class Container implements Component {
private Component [] children;
}
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The relationship between Animal and Species is a "has-a" relationship because Animal "has-a" Species.
The relationship between Container and Component is an "is-a" relationship because Container implements Component. A "has-a" relationship also exists because Container has a field that is an array of Container.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic