java学习笔记4:对象的初始化顺序(官方实例)
public class Insect {
int i=9;
int j;
Insect()
{
prt("i="+i+",j="+j);
j=39;
}
static int x1=prt("static Insect.x1 initallize");
static int prt(String s)
{
System.out.println(s);
return 47;
}
}
public class Beetle extends Insect {
int k=prt("Beetle.k initialized");
Beetle()
{
prt("k="+k);
prt("j="+j);
}
static int x2=prt("static Beetle.x2 initialize");
static int prt(String s)
{
System.out.println(s);
return 63;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
prt("Beetle constructor");
Beetle b=new Beetle();
}
}
Code