class Meal{
Meal(){
System.out.println("meal()函数被调用");
}
}
class Bread{
Bread(){
System.out.println("bread()函数被调用");
}
}
class cheese{
cheese(){
System.out.println("cheese()被调用");
}
}
class lettuce{
lettuce(){
System.out.println("letture() 被调用");
}
}
class lunch extends Meal{
lunch(){
System.out.println("引用lunch(),构造函数被调用");
}
}
public class Sandwith extends lunch {
private Bread a=new Bread();
private cheese b=new cheese();
private lettuce c=new lettuce();
public Sandwith(){
System.out.println("创建sandwith构造函数+sandwith()");
}
public static void main(String[] args){
new Sandwith();
}
}
sandwith是继承了lunch,但是lunch是继承了meal,其中meal是作为一个基础类进行用的,如果把原始的object也算在里面的话,一共是4.
其递归顺序是会一直调用,直到,调用出最基础的类,是一个向上寻找基础类的一个过程。
而是是按照声明顺序进行调用的。构造器的构造方法是按照初始化基础类。
这部分比较简单,可根据源码自己进行调试