public class tmp2
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
Child c = new Child();
}
}
class Parent
{
static
{
System.out.println("parent::static_constructor_block");
}
{
System.out.println("parent::constructor_block");
}
Parent()
{
System.out.println("parent::constructor");
}
}
class Child extends Parent
{
static
{
System.out.println("Child::static_constructor_block");
}
{
System.out.println("Child::constructor_block");
}
Child(int _)
{
System.out.println("Child::delegate_constructor_block");
}
Child()
{
this(1/*调用委托构造,数字随意*/);
System.out.println("Child::constructor");
}
private Member _member = new Member();
}
class Member
{
static
{
System.out.println("Member::static_constructor_block");
}
{
System.out.println("Member::constructor_block");
}
Member(){
System.out.println("Member::constructor");
}
}
结果
parent::static_constructor_block
Child::static_constructor_block
parent::constructor_block
parent::constructor
Child::constructor_block
Member::static_constructor_block
Member::constructor_block
Member::constructor
Child::delegate_constructor_block
Child::constructor
网友评论