In our continuing example, the virtual machine is still trying to execute the
method main
of class Test
. This is an attempted active use (§12.4.1) of the class,
which is permitted only if the class has been initialized.
Initialization consists of execution of any class variable initializers and static initializers of the class Test
, in textual order. But before Test
can be initialized, its direct superclass must be initialized, as well as the direct superclass of its direct superclass, and so on, recursively. In the simplest case, Test
has Object
as its implicit direct superclass; if class Object
has not yet been initialized, then it must be initialized before Test
is initialized. Class Object
has no superclass, so the recursion terminates here.
If class Test
has another class Super
as its superclass, then Super
must be initialized before Test
. This requires loading, verifying, and preparing Super
if this has not already been done and, depending on the implementation, may also involve resolving the symbolic references from Super
and so on, recursively.
Initialization may thus cause loading, linking, and initialization errors, including such errors involving other types.
The initialization process is described further in §12.4.