CLASSES
Static Initializers
8.5
A different compile time error now occurs, because the body of the method
move
cannot throw a checked exception, namely
BadPointException
, that does not
appear in the
throws
clause for
move
.
8.5 Static Initializers
Any
static initializers
declared in a class are executed when the class is initialized
and, together with any field initializers ( 8.3.2) for class variables, may be used to
initialize the class variables of the class ( 12.4).
StaticInitializer:
static
Block
It is a compile time error for a static initializer to be able to complete abruptly
( 14.1, 15.5) with a checked exception ( 11.2).
The static initializers and class variable initializers are executed in textual
order and may not refer to class variables declared in the class whose declarations
appear textually after the use, even though these class variables are in scope. This
restriction is designed to catch, at compile time, circular or otherwise malformed
initializations. Thus, both:
class Z {
static int i = j + 2;
static int j = 4;
}
and:
class Z {
static { i = j + 2; }
static int i, j;
static { j = 4; }
}
result in compile time errors.
Accesses to class variables by methods are not checked in this way, so:
class Z {
static int peek() { return j; }
static int i = peek();
static int j = 1;
}
175
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved