Skip to main content

Polymorphism in java

Polymorphism Concept
  • An object showing different behavior at different stages of its life cycle
    is known as polymorphism.
  • Two types of polymorphism
    1. Compile time polymorphism
    2. Run time polymorphism
Compile time polymorphism
  • In compile time polymorphism method declaration is binded to method
    implementation at the time of compilation by compiler.
  • This type of binding is known as static binding or early binding.
  • The compile time binding happen for static method , final method and overload method.
  • The binding done at compile time can not be re-binded.
  • Example of compiletime polymorphism~ Method overloading
    ~ Constructor overloading
    ~ Static method and final method
Run time polymorphism
  • In run time polymorphism method body is binded to method implementation
    at run time based on instance created.
  • This type of binding known as dynamic binding or late binding.
  • Method overriding is example of run time polymorphism.
  • To achieve runtime polymorphism we need to full feel following concept1. Inheritance
    2. Method overriding
    3. Up casting
  • With the help of runtime polymorphysm you can achieve
    – Generalization
    – Abstraction
    – Loose coupling