Difference Between Static And Dynamic Polymorphism

Polymorphism is one of the essential OOPs feature that can be defined as “ability to take multiple forms”. Programming languages such as Java, C++ use method overloading and method overriding to implement this OOPs feature.

However, it can be classified into Static and Dynamic polymorphism ( Runtime Polymorphism ) . The main difference between them is, one is resolved at compile-time and other resolved at run time.

Difference Between Static And Dynamic Polymorphism ( Runtime Polymorphism )?

BasisStatic PolymorphismRuntime Polymorphism
DefinitionIt can be defined as a process in which a function call with an object resolve at compile time by the compilerIt can be defined as a process in which a function call with an object resolve at runtime
Call ResolutionCall is settled by the compilerCall isn't settled by the compiler
Other NameCompile-time Polymorphism and Early bindingDynamic binding and Late binding
Achieved ByFunction overloading and Operator overloadingPointers and virtual functions
ExecutionIt is analyzed early at compile time so it provides fast executionIt is slow because it is analyzed at the runtime
FlexibilityIt is managed and executed at compile time which makes it less flexibleIt is more flexible because of its execution at runtime

Static Polymorphism

Static polymorphism is additionally termed as compile-time polymorphism, which implies that one can write numerous methods in a program with the same name, performing distinctive tasks.

However, it gives the client or the software engineer efficient and better comprehensibility of code.

Runtime Polymorphism ( Dynamic Polymorphism )

This is otherwise called Dynamic Polymorphism. It is a procedure in which a call to an overridden method is settled at runtime, which is the reason it is termed as runtime polymorphism.

Key differences

  • In Static Polymorphism, the call is settled by the compiler, whereas; In Run time Polymorphism, the call isn’t settled by the compiler.
  • It is otherwise called as Compile-time Polymorphism and Early binding, whereas; it is otherwise called Dynamic binding, Late binding and overriding also.
  • Overloading is compile-time polymorphism where more than one functions share a similar name with various parameters or signature and distinctive return type, whereas; Overriding is run time polymorphism having the same function with the same parameters or mark, however, related in a class and its subclass.
  • Static polymorphism is accomplished by function overloading and operator overloading, whereas; Runtime polymorphism is accomplished by pointers and virtual functions.
  • As in static polymorphism, it is analyzed early at compile time so it provides fast execution, whereas; Runtime polymorphism is slow because it is analyzed at the runtime.
  • In Static polymorphism, all the stuff is managed and executed at compile time which makes it less flexible, whereas; Runtime polymorphism is more flexible because of its execution at runtime.

Note: If you think, anything is wrong with the article, please inform us at inform@programmerbay.com

Leave a Reply