☰
d2jsp
Rules
Help
Forum Gold FAQ
Live Streams
Photo Gallery
Hourly Raffle
Ladder Slasher
Log In
Register
Log In
Register
Account Recovery
Resend Validation Email
d2jsp Forums
>
Off-Topic
>
Computers & IT
>
Programming & Development
> Method Overloading
Add Reply
New Topic
New Poll
Views: 278
Replies: 4
Track Topic
ferf
Member
Posts: 31,391
Joined: Mar 25 2009
Gold
:
99.00
#1
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?
labatymo
Member
Posts: 2,754
Joined: Nov 26 2007
Gold
:
1,339.81
#2
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.
ferf
Member
Posts: 31,391
Joined: Mar 25 2009
Gold
:
99.00
#3
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!!
labatymo
Member
Posts: 2,754
Joined: Nov 26 2007
Gold
:
1,339.81
#4
Oct 20 2017 11:26am
Sorry, I thought you said override.
Yes, you can actually do this, as long as the arguments are different.
ferf
Member
Posts: 31,391
Joined: Mar 25 2009
Gold
:
99.00
#5
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
© 2003-2024 d2jsp
Contact