首页 > 编程语言 > 详细

java 类和继承

时间:2021-03-06 10:37:07      阅读:26      评论:0      收藏:0      [点我收藏+]

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

java 类和继承

原文:https://www.cnblogs.com/ligenyun/p/14489358.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!