java 类和继承

参考: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

天生我材必有用,千金散尽还复来
原文地址:https://www.cnblogs.com/ligenyun/p/14489358.html