public class FatherClass
{
static
{
System.out.println("father static block");
}
{
System.out.println("father block");
}
public FatherClass()
{
System.out.println("father structuer");
}
}
public class CodeRunOrder extends FatherClass
{
static{
System.out.println("child static block");
}
{
System.out.println("child block");
}
public CodeRunOrder()
{
System.out.println("child structure");
}
public static void main(String[] args)
{
CodeRunOrder aCodeRunOrder=new CodeRunOrder();
}
}
最后的结果是:
father static block
child static block
father block
father structuer
child block
child structure
结论:
优先级static>>>father>>block>structure
最明显的用处是:
father structure>child block。
因为father的优先级要大于block对structure的优先级。