当前位置:网站首页>重载和重写的区别
重载和重写的区别
2022-06-21 22:26:00 【沉默小管】
重载
相同的方法名,形参数量不同或者参数顺序不同或者参数类型不同称为方法重载
class animal{
function cat(move string){
//A
console.log("貓喜歡"+move);
}
function cat(age int){
//A
console.log("貓"+age+"岁");
}
function cat(move string,age int){
//A
console.log("貓喜歡"+move+",同时"+age+"岁");
}
}
重写
重写方法前提:必须存在继承关系
方法名和形参列表相同
class animal{
function cat(move string){
console.log("貓喜歡"+move+",同时13岁");
}
}
class cat extends animal{
function cat(move string){
console.log("貓喜歡"+move+",同时16岁");
}
}

多态就是同一个接口,使用不同实例,执行不同操作
总结:
(1)方法重载是:一个类中定义了多个方法名相同,而他们的参数的数量不同或数量相同而类型和次序不同,则称为方法的重载(Overloading)。
(2)方法重写是:在子类存在方法与父类的方法的名字相同,而且参数的个数与类型一样,返回值也一样的方法,就称为重写(Overriding)。
(3)方法重载是一个类的多态性表现,而方法重写是子类与父类的一种多态性表现。
参考网址:https://www.runoob.com/java/java-override-overload.html
欢迎加入前端全栈开发交流圈一起吹水聊天学习交流qq群:837051545
个人网站:沉默小管
如有错误,请多多指教。
如对你有帮助,给个赞吧。
边栏推荐
- 一文看尽物体检测中的各种FPN
- Win11 how to change the desktop file path to disk D
- 数据库每日一题---第19天:排名靠前的旅行者
- spacy.load(“en_core_web_sm“)###OSError: [E050] Can‘t find model ‘en_core_web_sm‘.
- Redis master-slave replication (9)
- 编程干货│PHP 常见方法封装
- JVM makes wheels
- Reddit product director: a necessary NFT member practical guide for Web3 creators
- CVPR2022 | 弱监督多标签分类中的损失问题
- Component value transfer: value transfer between siblings (value transfer by non parent and child components)
猜你喜欢

En juin, le classement des langues de programmation a été publié et la langue doit être « féodale ».

Win11打字不显示选字框怎么办?Win11打字不显示选字框的解决方法

组件传值:子组件向父组件传递数据
![Shenzhen Data Analyst Certification (CPDA) in the second half of 2022, [enter to view]](/img/9a/4fe513a71f5efc7cce318708d6931e.jpg)
Shenzhen Data Analyst Certification (CPDA) in the second half of 2022, [enter to view]

Oracle flashback and RMAN samples

ERP已死,管理后台已凉,秒杀系统称王!

Student management system experiment report -asp Net programming

火线沙龙第26期-多云安全专场
![Infant name [adjacency matrix and DFS of connected components]](/img/60/83da6ce2fd2336fe1c4aead3260b77.png)
Infant name [adjacency matrix and DFS of connected components]

Layout roadmap, the perfect combination of spatial layout and data visualization
随机推荐
Shenzhen Data Analyst Certification (CPDA) in the second half of 2022, [enter to view]
pytorch可视化
Win11热点连接成功但没网?Win11移动热点和网络冲突的解决方法
MNIST image classification and comparison based on K-nearest neighbor
一文看尽物体检测中的各种FPN
被八股文害惨了。。。。
Analysis of Eureka
转载:网络加载框架 - Retrofit
Online text batch inversion by line tool
katalon Recoder常用命令
The ranking list of programming languages has been published in June, and this language should be "gods"
Mono 的創建
Component value transfer: value transfer between siblings (value transfer by non parent and child components)
Katalon框架测试web(八)等待
Jmter test command [note]
Academician Zhang Jun: the latest paper on unmanned intelligence group and its social integration, Journal of the Chinese Academy of Engineering
Redis master-slave replication (9)
Here comes the CV overview of target detection, visual weakly supervised learning, brain multimodal imaging technology and so on! Image graphics development annual report review special issue!
Component value transfer: props are used for parent component and child component value transfer
ARM汇编中的伪指令