There are two ways of overloading java methods. Changing the number of parameters. Changing data types. Overloading Java method by c...
There are two ways of overloading java methods.
- Changing the number of parameters.
- Changing data types.
Overloading Java method by changing parameters example
public class Calculate {
void divideNumbers(int a,int b,int c)
{
int result=(a+b+c)/5;
System.out.println("Answer is "+result);
}
void divideNumbers(int a,int b)
{
int result=(a+b)/5;
System.out.println("Answer is "+result);
}
Calculate()//Class constructor
{
divideNumbers(1234,235,675);//Calling methods
divideNumbers(342,123);
}
public static void main(String args[])
{
new Calculate();
}
}