Variables declared within the body of a method are local to that method. For example, the following code snippet declares an integer member variable named anInteger within the class IntegerClass . When you declare a variable like this, you declare an instance variable . This is in constrast to class variables which occur once per class regardless of the number of instances created of that class. The system allocates memory for class variables the first time it encounters the class.
All instances share the same copy of the class's class variables.
Class Variables A Variable's Type Every variable in a Java program must have a type. A variable's type determines the values that the variable can have and the operations that can be performed on the variable. The following table lists all of the simple data types supported by the Java language, the keyword that you use to declare a variable of that type, and the size of the variable. Complex types include classes, interfaces, and arrays. In essence, whenever you create a new class or interface, you are inventing a new data type.