4.5.3 Kinds of Variables

There are seven kinds of variables:

Were it not for one exceptional situation, a local variable could always be regarded as being created when its local variable declaration statement is executed. The exceptional situation involves the switch statement (§14.9), where it is possible for control to enter a block but bypass execution of a local variable declaration statement. Because of the restrictions imposed by the rules of definite assignment (§16), however, the local variable declared by such a bypassed local variable declaration statement cannot be used before it has been definitely assigned a value by an assignment expression (§15.25).

The following example contains several different kinds of variables:


class Point {
	static int numPoints;								// numPoints is a class variable
	int x, y;								// x and y are instance variables
	int[] w = new int[10];								// w[0] is an array component
	int setX(int x) {								// x is a method parameter
		int oldx = this.x;							// oldx is a local variable
		this.x = x;
		return oldx;
	}
}