Table of contents
Why Polymorphism ?
Ans:- If I give a real-time example... we are using social media like Facebook, Instagram, YouTube, etc... Their application is allocating more space/memory. So, performance will be decreased.
That's why are using a separate application like VIDMATE. This vidmate has all these 3 applications (Facebook, Instagram, YouTube). So, less memory is allocated and performance will increase, but Vidmate can open only one application at a time. So, we should go for polymorphism.
What is Polymorphism ?
Ans:- An object showing different behavior at different stages of its life cycle is called polymorphism.
Polymorphism means:- poly means many AND Morphism means forms.
The word polymorphism means having many forms.
It is classified into two types:- 1) Compile Time Polymorphism and 2) Run Time Polymorphism
1) Compile Time Polymorphism:- The method declaration is binded to its definition at the compile time by the compiler based on the arguments passed is called Compile time polymorphism.
i) It is also called an EARLY BINDING. Because the class loader will load before the JVM.
ii) It is also called a STATIC BINDING.
iii) Method Overloading is an example of a compile time polymorphism.
2) Run Time Polymorphism:- The method declaration is getting binded to its definition at the run time by JVM based on the object created is called run time polymorphism.
i) It is also called LATE BINDING. Because the class loader will load after the JVM.
ii) It is also called DYNAMIC BINDING.
iii) Method Overriding is an example of runtime polymorphism.