aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Clarification on Sefl test - K&B book Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Clarification on Sefl test - K&B book" Watch "Clarification on Sefl test - K&B book" New topic
Author

Clarification on Sefl test - K&B book

Omer Haderi
Ranch Hand

Joined: Sep 27, 2006
Posts: 42
Hi there,

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.

Is this an errata or I miss something ?

Thank you.
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Ummmmmmmmm.....


but an object may have static references to other objects.


Game of words!!! "static references" Good!

Anybody comment please!


Regards,
cmbhatt


cmbhatt
Richard Boren
Ranch Hand

Joined: Mar 01, 2001
Posts: 233
And I was patting myself on the back for getting that one right.

Has-a relationship always rely on instance variables.


Should �variable� be left off?

static SomeObject obj = new SomeObject() ;

obj is a static variable. Yes?
obj is referencing a SomeObject instance. Yes?

Do I have this all wrong?

Richard
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Good Richard,

Reference variables can be static, but objects are not!!!



Regards,
cmbhatt
swarna dasa
Ranch Hand

Joined: Mar 15, 2007
Posts: 108
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
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
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
Still on the look out for a convincing answer... :roll:
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Hi ranchers,

perhaps read what Javier wrote here (some time ago):
http://www.coderanch.com/t/258840/java-programmer-SCJP/certification/Has-relationship


The errata could be found here:
http://www.coderanch.com/t/257589/java-programmer-SCJP/certification/SCJP-Errata-Updated


And, by the way, nothing can be an errata...


Yours,
Bu.


all events occur in real time
Srinivasan thoyyeti
Ranch Hand

Joined: Feb 15, 2007
Posts: 557
Hi Ranchers,

I feel there is difference guys.

Class Has-A staticObject.

ClassObject Has-A instanceObject.

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, T.Srinivasan
SCWCD 1.4(89%), SCJP 5.0(75%)
Pankaj Patel
Ranch Hand

Joined: Jul 13, 2006
Posts: 73
Are STATIC Object OR Reference IS a part of Object.
NO.
IT IS A PART OF CLASS.
SO IT(has-a Relation) IS TOTALLY DEPENDENT ON INSTANCE VARIABLE.


AM I RIGHT?
[ April 19, 2007: Message edited by: Pankaj Patel ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Clarification on Sefl test - K&B book