Compile time polymorphism vs Runtime polymorphism
Polymorphism is the process where the same action can be performed in a number of different ways. Java supports 2 types of polymorphism – Compile time and runtime. Compile time polymorphism Java supports compile-time polymorphism via method overloading.Method overloading allows us to define two or more methods with the same name within a class but with different parameter declarations. Consider the following code snippet: public class AdditionService {int add() {return 3+5;}int add(int i) {return i+i;}int add(int i,int j) {return i+j;}double add(double i,double j) {return i+j;}} This class has 4 methods with the name add. All four add methods differ in the parameters, so there is no compilation error. 1 st add method does not have any parameters, the 2 nd add method takes two integer parameters, the 3 rd add method takes one integer parameter and the 4 th add method takes two double parameters. So the add method is said to be “overloaded” four times. Since the same action can be pe