Function overloading | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 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 ответ
+ 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