What are the differences between instance and class variables?

John Zukowski


You would use the static keyword to change an instance variable into a class variable.

Both instance and class variables are declared at the class level, not within methods:

public class Foo {
  static private int count; // class variable
  String name; // instance variable
  private void Bar() {
    int halfCount; // local variable

Note also that classes are loaded by classloaders therefore class variables are unique on a per-classloader basis.