博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java多态的实现 继承 重载 覆盖_Java基础篇(二、重载、继承、多态、覆盖重写)...
阅读量:4319 次
发布时间:2019-06-06

本文共 824 字,大约阅读时间需要 2 分钟。

以下为笔记整理主要参考视频教程:2019年idea版 java工程师基础班+旅游网项目实战,配合书Java的核心技术看,视频比较详细,本文仅供参考。

1、重载:

04e98e17df46?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

04e98e17df46?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

2、继承

继承中成员方法的特点(方法重名)

04e98e17df46?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

3、多态:

04e98e17df46?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

多态定义:

——>成员方法多态:

成员方法访问规则

04e98e17df46?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

04e98e17df46?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

——>成员变量的多态:

04e98e17df46?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

多态的好处:

04e98e17df46?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

对象的向上转型和向下转型:

04e98e17df46?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

04e98e17df46?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

4、覆盖重写:

——>区分重写和重载:

04e98e17df46?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

方法覆盖重写:

04e98e17df46?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

使用场景:

04e98e17df46?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

注意:实现过程,尽量不修改老的类,要覆盖重写添加新的内容

实例:

父类:

04e98e17df46?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

子类:

04e98e17df46?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

Main方法:

04e98e17df46?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

父子类构造方法:

构造方法:构造方法没有返回值,方法名和类名一样,其作用是用于在NEW一个类的时候,会总先调用这个类的构造方法,构造方法内部可以作一些变量的初始化或在创建这个类时必须调用的一些方法和运算,他是不用特意去调用的方法,会随着类的创建而自动去调用

04e98e17df46?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

supper关键字:

04e98e17df46?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

this关键字的三种用法:

04e98e17df46?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

内存示意:

04e98e17df46?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

5、继承:

04e98e17df46?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

抽象方法:

04e98e17df46?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

抽象类抽象方法:

父类是将子类所共同拥有的属性和方法进行抽取,这些属性和方法中,有的是已经明确实现了的,有的还无法确定,那么我们就可以将其定义成抽象,留给其子类去实现。

例如,定义了“动物”父类,其中“动物名称”和“动物年龄”属性已经明确了,但是“动物叫”的方法没有明确,此时就可以将“动物叫”定义为抽象方法。

04e98e17df46?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

多重继承:

04e98e17df46?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

转载地址:http://agrzs.baihongyu.com/

你可能感兴趣的文章
[js高手之路] es6系列教程 - 对象功能扩展详解
查看>>
java算法-选择排序
查看>>
python把字典写入excel之一例
查看>>
ROS配置C++14环境
查看>>
实现简单的登录界面
查看>>
项目管理有感之需求调研
查看>>
安装xampp之后如何建立远程登录用户并修改登录方式和密码
查看>>
linux下部署jenkins
查看>>
atitit.软件guibuttonand面板---os区-----软链接,快捷方式
查看>>
38平衡二叉树
查看>>
2替换空格
查看>>
如何修改settings.xml的镜像
查看>>
用IDEA/WebStrom 提交本地项目到Git/码云等
查看>>
JAVA笔记1__基本数据类型/输入输出/随机数/数组
查看>>
Linux 安装及配置 Nginx + ftp 服务器
查看>>
this 函数执行上下文
查看>>
Three.js 3D打印数据模型文件(.STL)载入中
查看>>
HOG特征-理解篇
查看>>
晨会的重要性
查看>>
poj 3735 大数量反复操作问题(矩阵高速幂)
查看>>