• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Clarification on Sefl test - K&B book

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ummmmmmmmm.....


but an object may have static references to other objects.



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

Anybody comment please!


Regards,
cmbhatt
 
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good Richard,

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



Regards,
cmbhatt
 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Still on the look out for a convincing answer... :roll:
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ranchers,

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


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


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


Yours,
Bu.
 
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Your mother is a hamster and your father smells of tiny ads!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic