What is polymorphism ?
Polymorphism means an ability to provide multiple functionalities with the same name to the user. “Poly” means many and “morph” means forms. Polymorphism is one of the main principles after encapsulation and inheritance in object oriented languages, it provides the ability to any class or function to provide many functionalities with the same name. “It is often called as one interface with many forms”.
Types of Polymorphism
- Static or Compile time :Static time or compile time polymorphism is an early binding method in which there are two types
a. Method overloading : In method overloading we can make methods of different functionalities with the same name. In method overloading we can define multiple methods with the same name but with different parameters and different return types.
b. Operator overloading :In operator overloading also we can change the functionality of existing operators. This technique is basically used to perform some basic operations on objects or in between two or more objects.
- Runtime polymorphism :Runtime polymorphism also known as late binding it actually get execute when the code get executed, it also have one type
a. Method overriding :In method overriding, methods with the same name are used in two different classes. This can be only possible using inheritance. In this method the method of base class or parent class is overridden in child classes.