The Class variable reference article from the English Wikipedia on 24-Jul-2004
(provided by Fixed Reference: snapshots of Wikipedia from wikipedia.org)

Class variable

Helping orphans the way you would do it
The term class variable is used in object-oriented programming to describe a variable that is associated with a class, not with a particular instance of the class. For example, a User class might have a class variable that refers to the currently logged on user, if only one user can ever log on at a time.

Static variables with public visibility are the object-oriented equivalent of global variables, because they can be accessed from anywhere in the application. Static variables with private visibility act as if they are shared by all instances of a class. If the value is changed by one instance, the changed value will be apparent to all other instances.

Class variables are also known as static variables. The class variables and class methods of a class are known collectively as class members or static members.

Class variables are implemented by allocating memory only once, instead of allocating memory for each instance of a class. In some languages this memory is allocated when the program is first started. Other languages, like Java, delay allocating this memory until the first time a constructor or static member of the class is accessed.

In Java a class variable is used like this:

public class User {
    private static User currentlyLoggedOnUser;

    public static User getCurrentlyLoggedOnUser() {
        return currentlyLoggedOnUser;
    }

    public boolean isCurrentlyLoggedOnUser() {
        return this == currentlyLoggedOnUser;
    }
}

A public class variable can be accessed from outside the class. If the class variable in the example above was public, you could access it like this:

if (user == User.currentlyLoggedOnUser) {
    System.out.println("User already logged on.");
}

See also: class method, instance variable