*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 4339
    
    7

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: 19649
    
  18

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
 
Consider Paul's rocket mass heater.
 
subject: Instance Variable vs. Class Variable
 
Similar Threads
doubt in has-a relationship
java (beginner)
What's the difference between instance variable and class variable?
Anonymous classes
Static final fields and final fields