d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Question About Methods
Add Reply New Topic New Poll
Member
Posts: 31,292
Joined: Mar 25 2009
Gold: 0.00
Mar 8 2017 08:51pm
new question ummm

how do you know which type to use for your method
for instance


void ferf() {
//body
}


how do i know what type to use, void, char, int, double, etc
Member
Posts: 36,123
Joined: Jul 18 2008
Gold: 2,407.00
Mar 9 2017 06:05am
Depends on what you need the method to do.
Member
Posts: 31,292
Joined: Mar 25 2009
Gold: 0.00
Mar 9 2017 04:28pm
Quote (Mastersam93 @ Mar 9 2017 08:05am)
Depends on what you need the method to do.


Can you be more specific with some examples?
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Mar 9 2017 07:42pm
getter vs setter is a simple example.
Member
Posts: 36,123
Joined: Jul 18 2008
Gold: 2,407.00
Mar 10 2017 06:05am
Quote (ferf @ Mar 9 2017 05:28pm)
Can you be more specific with some examples?



So if you need a function that is going to get a message from a user then you have that function return a String, because user message would be a string.

If the function is to find a square root of a number you would probably return a double, because the square root would probably be a double.

If you just want output a message to the screen and do nothing else, you would return void since you don't actually need a value to be returned at all. Although sometimes functions like these return a boolean, true for success and false for some kind of failure. It's up to you to decide how to do it.
Member
Posts: 31,292
Joined: Mar 25 2009
Gold: 0.00
Mar 10 2017 06:30am
Quote (Mastersam93 @ Mar 10 2017 08:05am)
So if you need a function that is going to get a message from a user then you have that function return a String, because user message would be a string.

If the function is to find a square root of a number you would probably return a double, because the square root would probably be a double.

If you just want output a message to the screen and do nothing else, you would return void since you don't actually need a value to be returned at all. Although sometimes functions like these return a boolean, true for success and false for some kind of failure. It's up to you to decide how to do it.


Thanks man <3
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll