+ 4

Can anyone explain the real time example of method overloading

java

27th Mar 2017, 9:04 AM
sudheer
sudheer - avatar
3 Antworten
+ 18
@sudheer msg me in person
29th Mar 2017, 5:04 PM
Prudhvi Raaj
Prudhvi Raaj - avatar
+ 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 ) }
27th Mar 2017, 9:56 AM
Anurag Bhattacharyya
Anurag Bhattacharyya - avatar
+ 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.
27th Mar 2017, 10:00 AM
Anurag Bhattacharyya
Anurag Bhattacharyya - avatar