2024年4月26日发(作者:)

package ;

public class Parent {

static Stub parentStaticStub = new Stub("parent static object-");

static {

n("parent static code excute");

}

Stub parentStub = new Stub("parent object-");

{

n("parent code excute");

}

Stub stub;

public Parent(){

n("parent constructor excute");

stub = new Stub("parent constructor created object-");

}

public void sayHello(){

n("hello from parent");

}

}

package ;

public class Child extends Parent{

static Stub childStaticStub = new Stub("child static object-");

static {

n("child static code excute");

}

Stub childStub = new Stub("child object-");

{

n("child code execute");

}

Stub stub;

public Child(){

n("child constructor excute");

stub = new Stub("child constructor create object-");

}

public void sayHello(){

n("hello from child");

}

}

package ;

public class TestParentChildExSequence {

public static void main(String[] args) {

Child child = new Child();

lo();

n("=====================================");

((Parent)child).sayHello();

}

}

开始分析: