Forums Register Login

has-a and static variables

+Pie Number of slices to send: Send
In the K&B Book is the answer of Self Test Questin 1 in Chapter 2:
Has-a relationships always rely on instance variables.

And what is about class (static) variables. Isn't that a has-a relationship, too?

Greetings
J�rg
+Pie Number of slices to send: Send
please send correct question no.
+Pie Number of slices to send: Send
It's in the SCJP 310-055, self test chapter 2, Question no 1.
The wright answer ist B, has-a relationship always rely on instance variables.

I think, has-a relationship rely on class variables, too.
+Pie Number of slices to send: Send
The static var exists before an instance is made...what object does have them, then? You can't have a Has-a relationships with the static var.
Im still studying maybe Im wrong but I dont think so.
I hope you understand what I mean...
+Pie Number of slices to send: Send
The definition of has-a in the book is: In Instance, that has a reference to the instance of another class.
So, in my opinion, a class variable is a reference to an instance, too. It's just the same instance for all objects of this class.
Arch enemy? I mean, I don't like you, but I don't think you qualify as "arch enemy". Here, try this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 841 times.
Similar Threads
static variables, methods
Static Keyword
HAS A doubt
Innerclass
Subclass Inheritence for protected variable
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 04:01:54.