1. What is polymorphism in java ?
All the very best!!
- The word polymorphism means that occurring many forms.
- In Java polymorphism is an OOPS concept.
- The ability of an object to have many different forms.
- Polymorphism happens in java when parent class reference is holding child class object.
- In java, polymorphism can be supported via method overloading, method overriding and inheritance.
- There are two different types of polymorphism available in java.
- Static binding or compile time polymorphism
- Dynamic binding or run time polymorphism
- compile time polymorphism is also known as method overloading.
- Method overloading happens with in a class or in parent and child class.
- Method overloading occurs when there are many methods exists with same name and
- Same method signature and different number of parameters.
- Same signature and same number of parameters but with different type of parameters.
- Different method signature and same or different number of parameters.
- run time polymorphism is also known as method overriding.
- Method overriding can not happen in same class.
- When two methods with same name and same signature in parent and child class is called method overriding.
- So the calling of actual method can be decided by JVM during run time based on the type of object that reference hold.
All the very best!!