Function overloading | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Function overloading

How functions can be distinguished in a program if they are having same name and number of arguments. Can return type be used???

31st Mar 2019, 5:48 AM
Alan
Alan - avatar
1 Answer
+ 3
Overloading is applicable only if we have different method signatures. In this case, combination of unique parameters with same method name. Therefore we can't have the method with same signatures of different return type as the compiler will have trouble pick the correct implementation. For example, ✅ OK double getArea ( int radius ) double getArea ( int width, int height ) ❎ NONO int getRate (double perecentage ) double getRate ( double percentage )
31st Mar 2019, 6:00 AM
Zephyr Koo
Zephyr Koo - avatar