重载和覆盖:有什么区别? [英] Overloading and overriding: what is the difference?

查看:129
本文介绍了重载和覆盖:有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

面向对象系统中的重载和覆盖之间有什么区别?

What is the difference between overloading and overriding in object-orientated systems?

推荐答案

覆盖时需要继承而不是重载。

In重载方法具有相同的返回类型,而在重载时它应该是不同的。

重写方法必须是公共的,而重载可能是不同的说明符。

如果仍然需要更多的区别请参阅以下链接。

谢谢。

http://goo.gl/eh9sx6 [ ^ ]
Overriding needs inheritance while overloading not.
In overriding method have same return type while in overloading it should be different.
Overriding method must be public while overloading may be different specifier.
If still you need more difference about this refer below link.
Thank you.
http://goo.gl/eh9sx6[^]


重载是何时你在同一个类中定义了两个具有相同名称但具有不同签名的方法。



覆盖是指重新定义已在父类中定义的方法时相同的签名。



重载在编译时解决。覆盖主要在运行时解决,具体取决于语言和情况。例如,C ++和C#在这方面很棘手,因为默认情况下,方法在运行时不能覆盖,但编译时(virtual关键字控制此行为)。然而,当C#编译器怀疑你出错时会发出警告。



希望有所帮助。
Overloading is when you define two methods with the same name in the same class but with different signatures.

Overriding is when you redefine a method that has already been defined in a parent class with ther same signature.

Overloading is resolved at compiletime. Overriding is mostly resolved at runtime, depending on language and situation. C++ and C# for example, are tricky in this respect, as methods are by default not overridable at runtime, but compile time (the virtual keyword controls this behaviour). The C# compiler will however issue warnings when it suspects you have got it wrong.

Hope that helps.


来吧,你是认真的吗?只需使用谷歌或在维基页面上查看oop。
Come on, are you serious? Just use google or look on the wiki page for oop.


这篇关于重载和覆盖:有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆