Alex Rivera | Logout

Compile time polymorphism vs. run time polymorphism

Asked 2010-01-28T07:06:01.963
41

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

Edit
Report

2 Answers

25

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.

answered 2010-01-28T08:12:47.600
0

Because it's known at compile time which of your overloaded functions is called, but that is not always the case for an overridden function.

answered 2010-01-28T07:11:10.267

Your Answer