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

K&B static/instance variable clarification

 
Ajit Sawant
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

On page 217 (chapter 3), part of the code is as follow:
class Foo{
static int size=7;
.... rest of the code.
The description on the page calls the varibale size as an instance variable. Isn't this a class variable as it marked static?
Please clarify.
Thanks in advance.
Ajit
 
Ajit Sawant
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the above question, I'm referring to SCJP6 book by Kathy and Bert.
Thanks
Ajit
 
patrick avery
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are correct.
 
Rajshekhar Paul
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By looking at the program, I can say that it's a typo when the author explained the code. It should be mentioned as static variable as in the main method the variable is directly accessed without using the class instance.
 
Bert Bates
author
Sheriff
Posts: 8898
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Egads! I think you're correct. It's amazing how long stuff like that can sit there, in thousands of copies of books, across several editions of authoring, editing and reviewing, and never be found!

Anyway, thanks for the (very likely), catch, I've marked in my book.

Bert
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic