0
В коде написано, что значение 5 возвращается в int. Именно в этот int, что написан перед именем метода ?
// returns an int value 5 static int returnFive() { return 5; }
3 Respuestas
+ 2
Yes, да.
static = You can access the method without using an object.
int = method will return an int (integer), in this situation 5.
returnFive = the name of the method.
() = a place for any parameters to input to the method.
{ = starts the method.
return 5; = the value the method will return. In this case 5. It can only return as an int.
if the method started: static double returnFive() the method would return 5.0.
} = ends the method.
+ 1
static int returnFive(){
return 5; ^
} ^
^
5 is returned and stored in "int" ?
In the definition of the method ?
0
Yes. The code will not compile without a return statement, and the value returned must be an int as declared.
So the moment this method is called 5 is stored as an int.
If in main() you say:
returnFive();
the integer dissapears into cyberspace
If you say:
int myFavoriteNumber = returnFive();
then it is the same as saying:
int myFavoriteNumber = 5;