Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HAS-A relation

 
Sarma Lolla
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q36
Which statements concerning the relationships between the following classes are true?
class Foo {
int num;
Baz comp = new Baz();
}
class Bar {
boolean flag;
}
class Baz extends Foo {
Bar thing = new Bar();
double limit;
}
1) A Bar is a Baz.
2) A Foo has a Bar.
3) A Baz is a Foo.
4) A Foo is a Baz.
5) A Baz has a Bar.
The correct answers mentioned are 3,5.
My answers are 2,3,5.
Can any one explain why answer 2 is wrong?
 
Larry Jones
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Foo dosen't have-a Bar.
In the code below, Foo has a Bar:

Baz, which extends Foo, has a Bar. But in OO terms, Foo does not have-a Bar.
For a has-a relationship, either a class, or a superclass must have a member that is a reference to the object.
[ March 13, 2003: Message edited by: Larry Jones ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic