先初始化父类的静态代码--->初始化子类的静态代码-->初始化父类的非静态代码--->初始化父类构造函数--->初始化子类非静态代码--->初始化子类构造函数
测试代码:
abstract class base
{
public int age=getNumber(100);
static{
System.out.println("base static block");
}
{
System.out.println("base nonstatic block");
}
static int sage=getNumber(50);
base(){
System.out.println(age);
System.out.println("base start");
draw();//会调用子类覆盖后的方法,这儿是0!
System.out.println("base end");
}
static int getNumber(int base){
System.out.println("base.getNumber int"+base);
return base;
}
public void draw(){
System.out.println("base.draw");
}
}
public class initializeOrder extends base{
public int age=getNumber(1001);
private int _radius=getNumber(10);
static int sage=getNumber(250);
static{
System.out.println("subclass static block");
}
{
System.out.println("subclass nonstatic block");
}
initializeOrder(int radius){
_radius=radius;
System.out.println(age);
draw();//这儿是1000
System.out.println("initializeOrder initialized");
}
public void draw(){
System.out.println("initializeOrder.draw "+_radius);
}
public static void main(String[] args) { // TODO Auto-generated method stub
new initializeOrder(1000);
}
}
输出为:
base static block
base.getNumber int50
base.getNumber int250
subclass static block
base.getNumber int100
base nonstatic block
100
base start
initializeOrder.draw 0
base end
base.getNumber int1001
base.getNumber int10
subclass nonstatic block
1001
initializeOrder.draw 1000
initializeOrder initialized