当前位置:网站首页>Rewriting and overloading
Rewriting and overloading
2022-07-22 07:02:00 【It could be something else】
1. rewrite (Override)
It's in the inheritance system , A subclass that implements a method that is identical in method declaration to the parent class .
To satisfy the inside substitution principle ( The child class replaces the parent class ), There are three limitations to rewriting :
A subclass method must have access greater than or equal to a superclass method ;
The return type of a subclass method must be the return type of a parent method or its child .
The exception type thrown by a subclass method must be the exception type thrown by the parent class or its subtype .
Use @Override annotation , You can ask the compiler to check if the above three constraints are met .
2. heavy load (Overload)
Exists in the same class , A method that has the same name as an existing method , But parameter types 、 Number 、 There is at least one difference in order .
It should be noted that , Different return values , Everything else being the same is not an overload .
边栏推荐
猜你喜欢
随机推荐
Foundation of Mathematics: Jensen inequality
Educational Codeforces Round 100 (Rated for Div. 2) B. Find The Array 题解
高通与苹果和解,获得至少45亿美元和解费!下一个目标:华为!
微信小程序列表渲染之上拉加载更多
Is there any age limit for opening an account? Excuse me, is it safe to open a stock account by mobile phone?
用原生js实现放大镜功能
2022.7.19 模拟赛
闻泰科技一季度营收同比猛增184.6%,净利润暴涨256.21%!
MODIS数据wget下载
qt中xxx.pro学习
小记录
3D sensing市场加速爆发,TOF和结构光谁将更胜一筹?
ENVI shp转roi并对栅格进行掩膜提取
三星Galaxy Fold拆解:内部极其复杂,铰链成屏幕损坏主因?
关于性能测试的这点事,干货来袭「建议收藏」
【数学基础】 foundation of mathematics :NPC问题
Airtest踩过的坑--启动闪退
模板方法模式
微信小程序列表(数据渲染之列表渲染)
EF linq杂记