当前位置:网站首页>The difference between overloading and rewriting
The difference between overloading and rewriting
2022-07-26 07:53:00 【I like iced black tea】
List of articles
The difference between overloading and rewriting
One 、 heavy load
heavy load (overloading) It's in a class , The method name is the same , And the parameters are different . The return type can be the same or different .
Every overloaded method ( Or constructors ) There must be a unique list of parameter types .
The most common place is the overloading of construction methods .
Overloads are in the same class with the same method name , Different parameters ( Number , type , The order ) Definition of the method of ,
Construction method common method , Abstract methods can be overloaded ; Rewriting is when a subclass inherits from its parent class ,
The method overridden in the subclass must be exactly the same as the parent method , It can be used @override Check whether it is an override method
Overload rule :
- The overloaded method must change the parameter list ( Number of parameters , Different type or order );
- Overloaded methods can change the return type ;
- Overloaded methods can change access modifiers ;
- Overloaded methods can declare new or broader check exceptions ;
- Methods can be overloaded in the same class or in a subclass .
- Cannot use return value type as distinguished standard of overloaded function .
Two 、 rewrite
Rewriting is a subclass's rewriting of the implementation process of the parent's accessible methods , Neither the return value nor the parameter can be changed . That is, the shell remains the same , Core rewrite !
The advantage of overriding is that subclasses can be as needed , Define your own actions . That is to say, the subclass can implement the methods of the parent class as required .
An overriding method cannot throw a new check exception or an exception that is broader than the overriding method declaration . for example : A method of the parent class declares a check exception IOException, But when overriding this method, it cannot be thrown Exception abnormal , because Exception yes IOException Parent class of , Throw out IOException Abnormal or IOException Subclass exception of .
In the object-oriented principle , Overriding means that you can override any existing method
3、 ... and 、 The difference between overloading and rewriting
| Difference point | Overloading methods | Rewriting methods |
|---|---|---|
| parameter list | Must be modified | It must not be modified |
| Return type | You can modify | It must not be modified |
Method rewrite (Overriding) And overloading (Overloading) yes java Different manifestations of polymorphism , Rewriting is a manifestation of polymorphism between parents and children , Overloading can be understood as a concrete manifestation of polymorphism .
- (1) Method overloading is defined in a class with more than one method with the same name , The number of parameters is different or the number is the same, but the type and order are different , It's called method overloading (Overloading).
- (2) Method rewriting is when a subclass has a method with the same name as the parent's method , And the number of parameters is the same as the type , The return value is the same way , It's called rewriting (Overriding).
- (3) Method overloading is a polymorphic representation of a class , Method rewriting is a kind of polymorphism between subclass and parent class .
边栏推荐
- Dynamic performance view overview
- Utils connection pool
- ARIMA model for time series analysis and prediction
- 「论文笔记」Next-item Recommendations in Short Sessions
- Quantitative perception training in tensorflow2.x and x86 end evaluation of tflite
- No valid host was found when setting up openstack to create an instance There are not enough hosts available. code:500
- System architecture & microservices
- 模型剪枝三:Learning Structured Sparsity in Deep Neural Networks
- Learning Efficient Convolutional Networks Through Network Slimming
- 2022.7.22DAY612
猜你喜欢

Enterprise private network construction and operation and maintenance

Matlab-二/三维图上绘制黑点

音视频学习(十)——ps流

Command line execution and test report generation of JMeter performance test

Network trimming: a data driven neuron pruning approach towards efficient deep architectures paper translation / Notes

DCN (deep cross network) Trilogy

Jmeter性能测试之使用存储响应内容到文件监听器

JMeter性能测试之使用CSV文件参数化

Idea settings set shortcut keys to convert English letters to case in strings

What is message subscription and publishing?
随机推荐
JMeter性能测试之使用CSV文件参数化
OVS underlying implementation principle
Web page basic label
Learning Efficient Convolutional Networks Through Network Slimming
Quantitative perception training in tensorflow2.x and x86 end evaluation of tflite
一文掌握mysql数据库审计特点、实现方案及审计插件部署教程
Deep learning model deployment
Master slave database deployment
Brief description of hystrix configuration
Comparison and difference between dependence and Association
DADNN: Multi-Scene CTR Prediction via Domain-Aware Deep Neural Network
Summarize the common high-frequency interview questions of the software testing post
【uniapp】多种支付方式封装
Jmeter性能测试之使用存储响应内容到文件监听器
Interview question set
dcn(deep cross network)三部曲
Shardingjdbc pit record
OVS底层实现原理
C language keyword extern
给项目日志加上traceid