参考:https://www.cnblogs.com/dolphin0520/p/3803432.html
1.初始化
2.构造函数
3.单类的执行顺序,先1后2;
4.继承:先父类,再子类。
5.成员变量,成员方法,都只继承public,protected的,private不继承。
6.static和final方法,不能继承和覆盖。成员变量,同理。
public class Test { public static void main(String[] args) { new Circle(); } } class Draw { public Draw(String type) { System.out.println(type+" draw constructor"); } } class Shape { private Draw draw = new Draw("shape"); public Shape(){ System.out.println("shape constructor"); } } class Circle extends Shape { private Draw draw = new Draw("circle"); public Circle() { System.out.println("circle constructor"); } }
输出:
shape draw constructor
shape constructor
circle draw constructor
circle constructor