阅前声明: http://blog.csdn.net/heimaoxiaozi/archive/2007/01/19/1487884.aspx
/****************** Exercise 17 *****************
* Create a class with a static String field that
* is initialized at the point of definition, and
* another one that is initialized by the static
* block. Add a static method that prints both
* fields and demonstrates that they are both
* initialized before they are used.
***********************************************/
public class E17_StaticStringInitialization {
static String s1 = "Initialized at definition";
static String s2;
static {
s2 = "Initialized in static block";
}
public static void main(String args[]) {
System.out.println("s1 = " + s1);
System.out.println("s2 = " + s2);
}
}
//+M java E17_StaticStringInitialization
**main( ) is a static method, so I just used that to print out the values.