Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Confused with a particular sentence in Kathry's and Bert's Book

 
Hussain Sabir
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which statement(s) are true? (Choose all that apply.)
A. Has-a relationships always rely on inheritance.
B. Has-a relationships always rely on instance variables.
C. Has-a relationships always require at least two class types.
D. Has-a relationships always rely on polymorphism.
E. Has-a relationships are always tightly coupled.
Answer:
® 3 B is correct.
®˚ A and D describe other OO topics. C is incorrect because a class can have an instance of
itself
. E is incorrect because while has-a relationships can lead to tight coupling, it is by no
means always the case. (Objective 5.5)
2. Given:
class Clidders

Guys ,

I'm not able to convince my mind with answer C above,could anyone please give me an example for this kind of Has-A relationship.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34422
347
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose you have a bag class. It could have an attribute for another bag. (I smaller one that you roll up and put inside.) So a Bag would "have" a Bag. One class.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12127
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
another example would be a linked list. each node has-a reference to a previous or a next node.
 
Hussain Sabir
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That explains everything(Wondering, why I didn't thought this way,probably because my Brain battery was down last night ).
cheers guys, Javaranch Rocks!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic