Polymorphism refers to an object's ability to exhibit different behaviors at various stages of its lifecycle, categorized into compile time and run time polymorphism. Compile time polymorphism, or static binding, occurs when method declarations are bound to their definitions at compile time, exemplified by method overloading. Run time polymorphism, or dynamic binding, occurs at runtime when method declarations are bound to definitions based on the created object, with method overriding as its example, providing benefits like loose coupling and generalization.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
4 views1 page
Polymorph Is M
Polymorphism refers to an object's ability to exhibit different behaviors at various stages of its lifecycle, categorized into compile time and run time polymorphism. Compile time polymorphism, or static binding, occurs when method declarations are bound to their definitions at compile time, exemplified by method overloading. Run time polymorphism, or dynamic binding, occurs at runtime when method declarations are bound to definitions based on the created object, with method overriding as its example, providing benefits like loose coupling and generalization.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1
POLYMORPHISM
An object showing different behaviour at different stages of its lifecycle is
called polymorphism. Poly means “ many “ , morphism means “ forms “
In polymorphism , we have 2 types
1. compile time polymorphism 2. run time polymorphism
1. COMPILE TIME POLYMORPHISM
The method declaration getting binded to its definition at the compile time by the compiler based on the arguments passed is called “ compile time polymorphism / static binding”. Since the method declaration getting binded to its definition at the time itself is called as “ early binding “. Once the method declaration gets binded to its definition it cannot be rebinded , hence it is called “ static binding” . ➢ Method overloading is an example for “ compile time polymorphism”. ➢ At the compile time it’s going to check for method declaration and its definition.
2. RUN TIME POLYMORPHISM
The method declaration gets binded to its definition at the run time by the JVM based on the object created is called as “ run time polymorphism/ Dynamic binding “. Since the method declaration gets binded to its definition , at the run time , hence it is called as “ late binding “. Since the method declaration gets binded to its definition , at the rebinded , hence it is called as “ Dynamic binding “. ➢ Method overriding is an example for runtime polymorphism .
Why do we go for run time polymorphism ?
To achieve 1. Single point of contact 2. loose coupling – If any internal enhancement is done it will not affect the usage. 3. Generalization – we can access everywhere.