Method overloading in Java means a class is having multiple methods with the same name but different in the parameter. Suppose you want to write an extensive program which contains many methods, remembering every method name might be difficult. So you can name every method with the same name but using different parameters. This is the coolness of method overloading.

Key points of Method Overloading in Java

  1. The name of all the methods should be the same but data type should be different from the parameters.
  2. If you took (int, int) as the data type for the parameters than for calling that method the data type should be (int, int) like (20,30).
  3. If you are using int method_name than there should be a return statement inside that method.Whereas in the case of void method_name, there is no need for the return statement.
  4. If you are using double as a parameter inside a method, then the data type for the method should be double. This means it should be equal to or higher than the data type used in the parameters. See the following example code.
double add(int a, int b, double c)

#java #java method overloading

Java Method Overloading Example | Method Overloading In Java
4.55 GEEK