KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > StaticInit


1 /**
2  * StaticInit
3  *
4  * Make sure static initializers work.
5  *
6  * @author <a HREF="ddp@apache.org">David Dixon-Peugh</a>
7  */

8
9 public class StaticInit implements org.quilt.cl.RunTest {
10     static StaticInit _instance;
11     static int value = -1;
12
13     static {
14         _instance = new StaticInit();
15         value = _instance.getValue();
16     }
17
18     public StaticInit() { }
19
20     public int getValue() {
21         return 3;
22     }
23
24     public static StaticInit getInstance() {
25         return _instance;
26     }
27     
28     public int runTest(int y) {
29         StaticInit si = getInstance();
30         int x = si.getValue();
31         return x + y;
32     }
33 }
34
Popular Tags