EXECUTION
Detailed Initialization Procedure
12.4.2
because the class
Sub
is never initialized; the reference to
Sub.taxi
is a reference
to a field actually declared in class
Super
and is not an active use of the class
Sub
.
Initialization of an interface does not, of itself, require initialization of any of
its superinterfaces. Thus, the test program:
interface I {
int i = 1, ii = Test.out("ii", 2);
}
interface J extends I {
int j = Test.out("j", 3), jj = Test.out("jj", 4);
}
interface K extends J {
int k = Test.out("k", 5);
}
class Test {
public static void main(String[] args) {
System.out.println(J.i);
System.out.println(K.j);
}
static int out(String s, int i) {
System.out.println(s + "=" + i);
return i;
}
}
produces the output:
1
j=3
jj=4
3
The reference to
J.i
is to a field that is a compile time constant; therefore, it does
not cause
I
to be initialized. The reference to
K.j
is a reference to a field actually
declared in interface
J
that is not a compile time constant; this causes initializa
tion of the fields of interface
J
, but not those of its superinterface
I
, nor those of
interface
K
. Despite the fact that the name
K
is used to refer to field
j
of interface
J
, interface
K
is not actively used.
12.4.2 Detailed Initialization Procedure
Because Java is multithreaded, initialization of a class or interface requires careful
synchronization, since some other thread may be trying to initialize the same class
or interface at the same time. There is also the possibility that initialization of a
225
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