当前位置:网站首页>The difference between overloading and rewriting
The difference between overloading and rewriting
2022-07-06 13:39:00 【Wake up duck, did you program today?】
First , This question is often asked in interviews , But there is nothing between the two
heavy load :
Occurs in the same class , Method name must be the same , Different reference types , The number is different. , Different order , Method return value and decoration can be different , Occurs at compile time .
rewrite :
Occurs in a parent-child class , Method name , The parameter list can be different , The return value range is less than or equal to the parent class , A subclass cannot throw more exceptions than its parent class , The subclass access modifier range is greater than or equal to the parent class ; If the parent method access modifier is private, Then the subclass cannot override the method
The following situation is also wrong , Will report a mistake :
// The following compilation will report errors
public int add(int a,int b)
public String add(int a,int b)
The above is my understanding of the difference between rewriting and overloading , If some friends have a better understanding , You can leave a message in the comment area !!!
边栏推荐
- Leetcode.3 无重复字符的最长子串——超过100%的解法
- String abc = new String(“abc“),到底创建了几个对象
- 透彻理解LRU算法——详解力扣146题及Redis中LRU缓存淘汰
- Set container
- 8. C language - bit operator and displacement operator
- 2.C语言矩阵乘法
- C language to achieve mine sweeping game (full version)
- There is always one of the eight computer operations that you can't learn programming
- C language Getting Started Guide
- 【九阳神功】2021复旦大学应用统计真题+解析
猜你喜欢
随机推荐
View UI Plus 發布 1.3.1 版本,增强 TypeScript 使用體驗
[au cours de l'entrevue] - Comment expliquer le mécanisme de transmission fiable de TCP
ROS machine voice
View UI Plus 发布 1.3.1 版本,增强 TypeScript 使用体验
List set map queue deque stack
Service ability of Hongmeng harmonyos learning notes to realize cross end communication
2.初识C语言(2)
The latest tank battle 2022 - full development notes-3
View UI plus released version 1.3.0, adding space and $imagepreview components
西安电子科技大学22学年上学期《射频电路基础》试题及答案
4. Binary search
六种集合的遍历方式总结(List Set Map Queue Deque Stack)
1.初识C语言(1)
关于双亲委派机制和类加载的过程
甲、乙机之间采用方式 1 双向串行通信,具体要求如下: (1)甲机的 k1 按键可通过串行口控制乙机的 LEDI 点亮、LED2 灭,甲机的 k2 按键控制 乙机的 LED1
【九阳神功】2022复旦大学应用统计真题+解析
View UI plus releases version 1.1.0, supports SSR, supports nuxt, and adds TS declaration files
最新坦克大战2022-全程开发笔记-3
一段用蜂鸣器编的音乐(成都)
7.数组、指针和数组的关系