+ 4
Can anyone explain the real time example of method overloading
java
3 Antworten
+ 18
@sudheer msg me in person
+ 12
public int sum (int a, int b)
{
int c;
c = a + b ;
return (c);
// this method is taking two integer parameters and returning their summation as a whole number ( integer )
}
public float sum (float a, float b)
{
float c;
c = a + b ;
return (c);
// this method is taking two floating point number parameters and returning their summation as a decimal number ( float )
}
+ 10
public int size(int a, int b)
{
return ( a * b );
}
public int size (int a, int b, int c)
{
return ( a * b * c );
}
// See here we are changing the number of parameters. To overload a method you have to either change number of parameters or type of parameters.