当前位置:网站首页>What is the difference between overload and override?

What is the difference between overload and override?

2022-06-24 00:01:00 The fifth brother of the Wang family

Method overloading and rewriting are ways to implement polymorphism , The difference is that the former implements compile time polymorphism , The latter implements runtime polymorphism .

heavy load : There are multiple methods with the same name in a class , But there are different parameter lists ( Different parameter types 、 The number of parameters is different or both are different ).

rewrite : Occurs between the subclass and the parent , Subclasses override the methods of the parent class , None of the parameters can be changed , Return value types can be different , But it must be a derived class of the return value of the parent class . That is, the shell remains the same , Core rewrite ! The advantage of overriding is that subclasses can be as needed , Define your own actions .

原网站

版权声明
本文为[The fifth brother of the Wang family]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206232121148710.html