Compile time polymorphism vs. run time polymorphism

后端 未结 9 2265
栀梦
栀梦 2020-12-23 00:15

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

9条回答
  •  无人及你
    2020-12-23 00:42

    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.

提交回复
热议问题