当前位置:网站首页>The difference between overloading and overriding
The difference between overloading and overriding
2022-06-22 00:16:00 【Silent tubule】
heavy load
The same method name , The number of formal parameters is different perhaps Parameter order is different perhaps Different parameter types are called method overloading
class animal{
function cat(move string){
//A
console.log(" Cats like "+move);
}
function cat(age int){
//A
console.log(" Cat "+age+" year ");
}
function cat(move string,age int){
//A
console.log(" Cats like "+move+", meanwhile "+age+" year ");
}
}
rewrite
Rewrite the premise method : There must be inheritance
The method name is the same as the formal parameter list
class animal{
function cat(move string){
console.log(" Cats like "+move+", meanwhile 13 year ");
}
}
class cat extends animal{
function cat(move string){
console.log(" Cats like "+move+", meanwhile 16 year ");
}
}

Polymorphism is the same interface , Use different instances , Perform different operations
summary :
(1) Method overloading is : Multiple methods with the same name are defined in a class , 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 override is : The name of the method that exists in the subclass is the same as that of the parent class , 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 .
Refer to the website :https://www.runoob.com/java/java-override-overload.html
Welcome to join the front-end full stack development exchange circle to blow water, chat, learn and exchange qq Group :837051545
Personal website : Silent tubule
If there is a mistake , Your advice are most welcome .
If it helps you , Give me a compliment .
边栏推荐
猜你喜欢

美国旅游签证面试须知,我来敲重点啦!

Neural networks and support vector machines for machine learning

Celery+rabbit distributed task processing

Isn't the so-called 0 copy just to let the CPU rest? Deep understanding of MMAP

Component value transfer: props are used for parent component and child component value transfer

Buuctf misc spy Apocalypse

张军院士:《无人智群及其社会融合》最新论文,中国工程院院刊

路由器连接上但上不了网是什么故障

Introduction to activities in the name of the father (you can collect sheep)

组件传值:父组件与子组件传值用props
随机推荐
rabbit:do_ run_ postlaunch_ phase/0 line 932
Analysis of Eureka
[GXYCTF2019]SXMgdGhpcyBiYXNlPw==
青春无言│用技术定格毕业季最美好的回忆
转载:网络加载框架 - Retrofit
一文看尽物体检测中的各种FPN
Google AI big model lamda can one day replace the search engine? Google researcher: search can be re imagined as a two-way dialogue between users and languages
Katalon recoder common commands
【next】nextjs打包后出现passHref is missing
Katalon framework testing web (XVIII) framework operation
Xshell连接虚拟机只能输入public key解决方案【亲测】
Creation of mono
如何使用tensorboard add_histogram
buuctf misc 间谍启示录
6月編程語言排行榜已出,這門語言要“封神”
谷歌AI大模型LaMDA有朝一日可取代搜索引擎?谷歌研究员:搜索可被重新想象成用户和语言之间的双向对话
以父之名活动攻略(可以薅羊毛啦)
En juin, le classement des langues de programmation a été publié et la langue doit être « féodale ».
张军院士:《无人智群及其社会融合》最新论文,中国工程院院刊
Programming dry goods │ PHP common method encapsulation