public class Demo3_2 {
static int i=1;
static //静态区域块
{
//该静态区域块只被执行一次
System.out.println("a"); //测试用
i++;
}
public Demo3_2()
{
System.out.println("b"); //测试用
i++;
}
public static void main(String []args)
{
Demo3_2 t1=new Demo3_2();
System.out.println(t1.i);
Demo3_2 t2=new Demo3_2();
System.out.println(t2.i);
}
}
运行结果:
a
b
3
b
4