Difference Between Runtime & Compile-Time Polymorphism

The word “poly” means many and “morphs” means forms, So it means many forms. Polymorphism is considered one of the important features of Object-Oriented Programming. Polymorphism allows us to perform a single action in different ways.

There are some key difference between Runtime and Compile Time Polymorphism :

FeatureCompile-Time PolymorphismRuntime Polymorphism
1. DefinitionCompile time Polymorphism in C++ determines which function or operation to call based on the number, types, and order of arguments.The decision of which function to call is determined at runtime based on the actual object type rather than the reference or pointer type.
2. BindingStatic binding, where the function calls are statically bound to their definitions.Dynamic binding, where the function calls are dynamically bound to their definitions.
3. Polymorphism TypeCompile-time Polymorphism, also known as static or early binding Polymorphism.Runtime Polymorphism, also known as late binding or dynamic Polymorphism.
4. Function OverloadingMultiple functions have the same name but different parameters defined. The compiler determines which function to call based on the number and types of arguments.Not applicable.
5. OperatorOverloading Operators can be overloaded to perform different operations based on the types of operands.Not applicable.
6. InheritanceNot involved.Involves inheritance, where a derived class overrides a function from its base class.
7. Execution SpeedFaster execution rate, as the compiler determines which function to call at compile-time.Comparatively slower execution rate, as the decision of which function to call is made at runtime.
8. Code ReusabilityHigh code reusability, as the same function name can be used with different parameters.High code reusability, as the same function name can be used with different object types.
9. Polymorphism In C++Compile-time Polymorphism is achieved by function overloading of operator overloading.Runtime Polymorphism is achieved by function overriding.
Difference Between Runtime and Compile Time Polymorphism

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *