public class HelloB extends HelloA
{
public HelloB()
{
}
{
System.out.println("I’m B class");
}
static
{
System.out.println("static B");
}
public static void main(String[] args)
{
new HelloB();
}
}
class HelloA
{
public HelloA()
{
}
{
System.out.println("I’m A class");
}
static
{
System.out.println("static A");
}
}
image.png
1岩臣、執(zhí)行父類的靜態(tài)代碼塊
static {
System.out.println("static A");
}
輸出:static A
2、執(zhí)行子類的靜態(tài)代碼塊
static {
System.out.println("static B");
}
輸出:static B
3宵膨、執(zhí)行父類的構(gòu)造代碼塊
{
System.out.println("I’m A class");
}
輸出:I'm A class
4架谎、執(zhí)行父類的構(gòu)造函數(shù)
public HelloA() {
}
輸出
5、執(zhí)行子類的構(gòu)造代碼塊
{
System.out.println("I’m B class");
}
輸出:I'm B class
6辟躏、執(zhí)行子類的構(gòu)造函數(shù)
public HelloB() {
}
輸出:無