Java support to define two or more methods with same names within a class. If we have to perform only one operation, having same name of methods increases the readability of program. All the methods should differ in either by the number or type of parameters. Suppose you have to perform addition of the given numbers but there can be any number of arguments if you write the method such as A (int, int) for two parameters and B(int, int, int) for three parameter then it may be difficult for you as well as other programmer to understand the behavior of the function method because it names differs so we perform method overloading.
Use of java method overloadingclass Class1{ public void multiply(int a,int b){ System.out.println(a*b); } public void multiply(int a,int b,int c){ System.out.println(a*b*c); } } public class AJTD6 extends Class1{ public static void main(String[] args) { AJTD6 a=new AJTD6(); a.multiply(10, 10, 10); a.multiply(20, 20); } }O/P
D:\classes>javac AJTD6.java D:\classes>java AJTD6 1000 400