Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

has-a and static variables

 
Joerg Waldmann
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
sandeep biradar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please send correct question no.
 
Joerg Waldmann
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Arno Reper
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Joerg Waldmann
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic