We can overload java methods by changing datatypes or changing the number of parameters the method will take. Overloading by changi...
We can overload java methods by changing datatypes or changing the number of parameters the method will take.
Overloading by changing datatypes example
public class Calculate { void divideNumbers(int a,int b) { int result=(a+b)/5; System.out.println("Answer is "+result); } void divideNumbers(double a,double b) { double result=(a+b)/5; System.out.println("Answer is "+result); } Calculate()//Class constructor { divideNumbers(12.34,235.5);//Calling methods divideNumbers(342,123); } public static void main(String args[]) { new Calculate(); } }