本文共 824 字,大约阅读时间需要 2 分钟。
以下为笔记整理主要参考视频教程:2019年idea版 java工程师基础班+旅游网项目实战,配合书Java的核心技术看,视频比较详细,本文仅供参考。
1、重载:
image.png
image.png
2、继承
继承中成员方法的特点(方法重名)
image.png
3、多态:
image.png
多态定义:
——>成员方法多态:
成员方法访问规则
image.png
image.png
——>成员变量的多态:
image.png
多态的好处:
image.png
对象的向上转型和向下转型:
image.png
image.png
4、覆盖重写:
——>区分重写和重载:
image.png
方法覆盖重写:
image.png
使用场景:
image.png
注意:实现过程,尽量不修改老的类,要覆盖重写添加新的内容
实例:
父类:
image.png
子类:
image.png
Main方法:
image.png
父子类构造方法:
构造方法:构造方法没有返回值,方法名和类名一样,其作用是用于在NEW一个类的时候,会总先调用这个类的构造方法,构造方法内部可以作一些变量的初始化或在创建这个类时必须调用的一些方法和运算,他是不用特意去调用的方法,会随着类的创建而自动去调用
image.png
supper关键字:
image.png
this关键字的三种用法:
image.png
内存示意:
image.png
5、继承:
image.png
抽象方法:
image.png
抽象类抽象方法:
父类是将子类所共同拥有的属性和方法进行抽取,这些属性和方法中,有的是已经明确实现了的,有的还无法确定,那么我们就可以将其定义成抽象,留给其子类去实现。
例如,定义了“动物”父类,其中“动物名称”和“动物年龄”属性已经明确了,但是“动物叫”的方法没有明确,此时就可以将“动物叫”定义为抽象方法。
image.png
多重继承:
image.png
转载地址:http://agrzs.baihongyu.com/