Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Instance Variable vs. Class Variable  RSS feed

 
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: 4568
9
  • 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
Posts: 21092
85
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!