What Happens If function have same name but different return type and different arguments.Is it overload or not. | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
- 1

What Happens If function have same name but different return type and different arguments.Is it overload or not.

Hi Sololearn First, thanks all of you for clearing my every doubts. My question is that what happens if we write function have same name but different return type and different arguments.Is it overload & override or no? Ex. Case 1: void fun(int x, int y) // Assume in parent class int fun( int x, int y) // Assume in child class Case 2: void fun ( int x, int y) // parent class void fun (int x, float y) // child class I think in case 1 overloading is not possible because of last Statment will changes ( return z will added in child class function). But what about overriding. Hmm I'm confused here And for case 2: I don't have any idea. Please answer.....

23rd Jun 2021, 2:16 AM
ㅤㅤㅤㅤㅤㅤ
ㅤㅤㅤㅤㅤㅤ - avatar
3 Respuestas
+ 3
Neither is overriden Override only happens when the methods are exactly same, including return type, method name, data type of arguments, etc. Overload is a bit different. Case 2 is overload-able in both Java and C++. The difference is in C++ you need to introduce the parent method to the child in the child class, while you don't need to in Java. Case 1 is not overload-able in both langauges.
23rd Jun 2021, 12:00 PM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 1
Please provide the language for the question.
23rd Jun 2021, 2:39 AM
你知道規則,我也是
你知道規則,我也是 - avatar
0
CarrieForle Any language. Java or C++
23rd Jun 2021, 7:26 AM
ㅤㅤㅤㅤㅤㅤ
ㅤㅤㅤㅤㅤㅤ - avatar