d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Method Overloading
Add Reply New Topic New Poll
Member
Posts: 31,391
Joined: Mar 25 2009
Gold: 99.00
Oct 20 2017 11:00am
Can you change return type of method for method overloading
for example:
public static int calculateScore(int num1, int num2)
public static void calculateScore(String Name, double num3)

switching from int to void... is that possible?
Member
Posts: 2,754
Joined: Nov 26 2007
Gold: 1,339.81
Oct 20 2017 11:08am
No this is not possible. You'll get a compile time error.

However, if the return type on the original method is abstract, then you can return an object that extends that abstract class.
Member
Posts: 31,391
Joined: Mar 25 2009
Gold: 99.00
Oct 20 2017 11:14am
Quote (labatymo @ Oct 20 2017 01:08pm)
No this is not possible. You'll get a compile time error.

However, if the return type on the original method is abstract, then you can return an object that extends that abstract class.


Thanks!!
Member
Posts: 2,754
Joined: Nov 26 2007
Gold: 1,339.81
Oct 20 2017 11:26am
Sorry, I thought you said override.

Yes, you can actually do this, as long as the arguments are different.
Member
Posts: 31,391
Joined: Mar 25 2009
Gold: 99.00
Oct 20 2017 11:41am
Quote (labatymo @ Oct 20 2017 01:26pm)
Sorry, I thought you said override.

Yes, you can actually do this, as long as the arguments are different.


oh okay, well ty :)
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll