What’s the difference between run-time polymorphism and compile-time polymorphism? Also, what’s the difference between early binding and late binding? Examples would be highly appreciated.
What’s the difference between run-time polymorphism and compile-time polymorphism? Also, what’s the difference between
Share
Compile Time Polymorphism
Method overloading is a great example. You can have two methods with the same name but with different signatures. The compiler will choose the correct version to use at compile time.
Run-Time Polymorphism
Overriding a virtual method from a parent class in a child class is a good example. Another is a class implementing methods from an Interface. This allows you to use the more generic type in code while using the implementation specified by the child. Given the following class definitions:
The following code will output “Goodbye World!”:
Early Binding
Specifying the type at compile time:
Late Binding
The type is determined at runtime: