编译时多态性与运行时多态性 [英] Compile time polymorphism vs. run time polymorphism

查看:199
本文介绍了编译时多态性与运行时多态性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么超载称为编译时多态性和压倒一切的运行时多态性在C#?

Why is overloading called compile time polymorphism and Overriding run time polymorphism in C#?

推荐答案

而被重写的功能是具有功能相同的签名,但在不同的派生类实现的。在编译的时候,通常是基类用于引用一个对象,但在运行时,这个对象可以是一个派生类型,因此,当一个重载方法被调用时,被调用的实现依赖于什么样的对象做主叫(基本与派生类型),这是在编译时未知。

Overridden functions are functions that have the same signature, but are implemented in different derived classes. At compile time, usually the base class type is used to reference an object, though at run time this object could be of a derived type, so when an overridden method is called, the implementation that is called is dependent on what kind of object is doing the calling (base vs. a derived type) which is unknown at compile time.

重载(不是真的多态性)仅仅是具有相同名称但不同的签名(想了一个对象采取的参数不同数量的多个构造函数)多种功能。这方法被调用在编译时是已知的,因为该参数在此时指定。

Overloading (not really polymorphism) is simply multiple functions which have the same name but different signatures (think multiple constructors for an object taking different numbers of arguments). Which method is called is known at compile time, because the arguments are specified at this time.

这篇关于编译时多态性与运行时多态性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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