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

Instance Variable vs. Class Variable

 
Patrick Day
Greenhorn
Posts: 8
Eclipse IDE Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been studying and came across this terminology, that thoroughly confused me. What exactly is the difference between an instance variable & class variables, are they not the same thing?
 
Matthew Brown
Bartender
Posts: 4566
8
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The way I'd expect the terminology to be used: for an instance variable, there's one variable belonging to each instance of the class. For a class variable, there's a single variable belonging to the class. In Java that corresponds to the variable being declared static.
 
Patrick Day
Greenhorn
Posts: 8
Eclipse IDE Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So...a class variable is just another term for a static variable or field?
 
Rob Spoor
Sheriff
Pie
Posts: 20510
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.
 
Patrick Day
Greenhorn
Posts: 8
Eclipse IDE Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic