public class java9_7
{
static String a="string-a";
static String b;
String c="string-c";
String d;
static
{
printStatic("before static");
b="string-b";
printStatic("after static");
}
public static void printStatic(String title)
{
System.out.println("--------"+title+"-------");
System.out.println("a=\""+a+"\"");
System.out.println("b=\""+b+"\"");
}
public java9_7()
{
print("before constructor");
d="string-d";
print("after constructor");
}
public void print(String title)
{
System.out.println("--------"+title+"-------");
System.out.println("a=\""+a+"\"");
System.out.println("b=\""+b+"\"");
System.out.println("c=\""+c+"\"");
System.out.println("d=\""+d+"\"");
}
public static void main(String args[])
{
new java9_7();
}
}
注意静态代码块的使用
最新推荐文章于 2022-08-04 11:36:44 发布