如下面代码
public class Test1
{
public static void main(String[] args)
{
Test2 t2 = new Test2();
System.out.println();
Test3 t3 = new Test3();
}
}
class Test2
{
static
{
System.out.println("Test2 static");
}
public Test2()
{
System.out.println("Test2 create");
}
}
class Test3 extends Test2
{
static
{
System.out.println("Test3 static");
}
public Test3()
{
System.out.println("Test3 create");
}
}
输出为:
Test2 static
Test2 create
Test3 static
Test2 create
Test3 create
如果把Test2 t2 = new Test2();注释掉,这时输出为:
Test2 static
Test3 static
Test2 create
Test3 create