This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
I have a question about the first question on self test page 158 K&B book.
It seems to me that none of the options is 100% correct, the book marks B. (Has-a relationship always rely on instance variables.), but an object may have static references to other objects.
Actually i too got it wrong and convinced myself that "HAS-A" makes sense only with instance variables. Though i am not completely convinced
Lets try this example (though not a perfect one)
Lets say Honda always have a particular kind of audio system (Bose) and this will never change (Remember its not a perfect example).
class Honda { final static BoseSpeakerSystem speaker = new BoseSpeakerSystem(); //can override other functions ... ... ... }
class BoseSpeakerSystem extends SpeakerSystem{ }
In this case can we say all Honda cars have a Bose Speaker System?
Omer Haderi
Ranch Hand
Joined: Sep 27, 2006
Posts: 42
posted
0
Hello again,
I couldn't find any good explanation for this, so I will try to get it right through another question... :roll:
if the following is considered to have a "Has-a" relationship then the answer b of the book is an errata.
otherwise I miss something from that question.
Richard Boren
Ranch Hand
Joined: Mar 01, 2001
Posts: 233
posted
0
Hi Omer,
The book says �Is-a� is based on class inheritance or interface (p. 90; 1st para under IS-A)
I don�t see enxtends or implenents in your example. So I�d say it is a �Has-a�. And obviously obj is not an "instance variable". It looks like answer (b) is not 100% correct as you have stated.
otherwise I miss something from that question.
Me too. Sorry no answer, same question.
Richard
swarna dasa
Ranch Hand
Joined: Mar 15, 2007
Posts: 108
posted
0
Still on the look out for a convincing answer... :roll:
When you say ClassObject has an Object, it must be in its ClassObjectState.
ClassObject can use/share the static context Objects. its common behavior for all ClassObjects to share static context.
Thanks & Regards,<br />T.Srinivasan,<br />SCWCD 1.4(89%),SCJP 5.0(75%)<br />"That service is the noblest which is rendered for its own sake." - Mahatma Gandhi