1、父类静态成员和静态初始化块,按在代码中出现的顺序依次执行
2、子类静态成员和静态初始化块,按在代码中出现的顺序依次执行
3、父类实例成员和实例初始化块,按在代码中出现的顺序依次执行
4、父类构造方法
5、子类实例成员和实例初始化块,按在代码中出现的顺序依次执行
6、子类构造方法
检验一下是不是真懂了:
public class Base {
private String name ="博客:Kaifamiao";
public Base(){
tellName();
printName();
}
public void tellName() {
System.out.println("Base tell name:"+ name);
}
public void printName() {
System.out.println("Base print name:"+ name);
}
}

public class Dervied extends Base {
private String name ="Java3y";
public Dervied(){
tellName();
printName();
}
@Override
public void tellName(){
System. out. println("Dervied tell name:"+ name);
}
@Override
public void printName(){
System.out. println("Dervied print name:"+ name);
}
public static void main(String[] args){
new Dervied();
}
}
输出数据:
Dervied tell name: null
Dervied print name: null
Dervied tell name: Java3y
Dervied print name: Java3y
Process finished with exit code O

Was this helpful?

0 / 0

发表回复 0

Your email address will not be published.