当前位置:网站首页>重载和重写的区别
重载和重写的区别
2022-07-06 09:20:00 【快醒醒鸭今天你编程了吗?】
首先,这道题面试常问,但是两个之间毫无任何关系
重载:
发生在同一个类当中,方法名必须相同,参考类型不同,个数不同,顺序不同,方法返回值和修饰可以不同,发生在编译时。
重写:
发生在父子类中,方法名,参数列表可以不同,返回值范围小于等于父类,子类不可以抛出比父类更多的异常,子类访问修饰符范围大于等于父类;如果父类方法访问修饰符为private,则子类就不能重写该方法
以下这种情况也是错误的,会报错:
//以下编译会报错
public int add(int a,int b)
public String add(int a,int b)
以上就是我对重写和重载区别的认识,要是有些小伙伴有更好的理解,可以评论区留言!!!
边栏推荐
- Branch and loop statements
- 3. Number guessing game
- 分支语句和循环语句
- Tyut Taiyuan University of technology 2022 introduction to software engineering summary
- 凡人修仙学指针-1
- There is always one of the eight computer operations that you can't learn programming
- 【话题终结者】
- TYUT太原理工大学2022数据库大题之数据库操作
- Alibaba cloud microservices (IV) service mesh overview and instance istio
- E-R graph to relational model of the 2022 database of tyut Taiyuan University of Technology
猜你喜欢
2.C语言初阶练习题(2)
The latest tank battle 2022 full development notes-1
Alibaba cloud side: underlying details in concurrent scenarios - pseudo sharing
5. Function recursion exercise
5.MSDN的下载和使用
最新坦克大战2022-全程开发笔记-2
学编程的八大电脑操作,总有一款你不会
TYUT太原理工大学2022数据库大题之概念模型设计
System design learning (III) design Amazon's sales rank by category feature
12 excel charts and arrays
随机推荐
六种集合的遍历方式总结(List Set Map Queue Deque Stack)
Conceptual model design of the 2022 database of tyut Taiyuan University of Technology
Tyut Taiyuan University of technology 2022 introduction to software engineering
Arduino+ water level sensor +led display + buzzer alarm
[中国近代史] 第五章测验
2. Preliminary exercises of C language (2)
【九阳神功】2019复旦大学应用统计真题+解析
View UI Plus 发布 1.2.0 版本,新增 Image、Skeleton、Typography组件
学编程的八大电脑操作,总有一款你不会
1.初识C语言(1)
(ultra detailed onenet TCP protocol access) arduino+esp8266-01s access to the Internet of things platform, upload real-time data collection /tcp transparent transmission (and how to obtain and write L
2. C language matrix multiplication
MySQL Database Constraints
System design learning (III) design Amazon's sales rank by category feature
[while your roommate plays games, let's see a problem]
12 excel charts and arrays
6.函数的递归
[中国近代史] 第九章测验
MySQL limit x, -1 doesn't work, -1 does not work, and an error is reported
View UI Plus 發布 1.3.1 版本,增强 TypeScript 使用體驗