Specifications

Sun Services
Java™ Programming Language
Module 7, slide 11 of 44
Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision F
Static Initializers
1 public class Count4 {
2 public static int counter;
3 static {
4 counter = Integer.getInteger("myApp.Count4.counter").intValue();
5 }
6}
1 public class TestStaticInit {
2 public static void main(String[] args) {
3 System.out.println("counter = "+ Count4.counter);
4 }
5}
The output of the TestStaticInit program is:
java -DmyApp.Count4.counter=47 TestStaticInit
counter = 47