8.1.1 Scope of a Class Type Name

The Identifier in a class declaration specifies the name of the class. This class name has as its scope (§6.3) the entire package in which the class is declared. As an example, the compilation unit:


package points;


class Point {
	int x, y;									// coordinates
	PointColor color;									// color of this point
	Point next;									// next point with this color
static int nPoints; }
class PointColor { Point first; // first point with this color PointColor(int color) { this.color = color; } private int color; // color components }

defines two classes that use each other in the declarations of their class members. Because the class type names Point and PointColor have the entire package points, including the entire current compilation unit, as their scope, this example compiles correctly-that is, forward reference is not a problem.