GeeCON Prague 2014*
The moose likes Java in General and the fly likes Instance Variable vs. Class Variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Instance Variable vs. Class Variable" Watch "Instance Variable vs. Class Variable" New topic
Author

Instance Variable vs. Class Variable

Patrick Day
Greenhorn

Joined: Jul 23, 2011
Posts: 8

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

Joined: Apr 06, 2010
Posts: 4397
    
    8

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

Joined: Jul 23, 2011
Posts: 8

So...a class variable is just another term for a static variable or field?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Yes.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Patrick Day
Greenhorn

Joined: Jul 23, 2011
Posts: 8

Thanks for the help
 
Don't get me started about those stupid light bulbs.
 
subject: Instance Variable vs. Class Variable