+ 1
What is method return value?
7 Respostas
+ 8
In JAVA, 'void' is used when you do not want your method to return anything.
In Java, while defining a method, you usually define following three things
with it :
1. Access specifiers such as public, protected.
2. Return type of the method.
3. Parameters to be passed in the method and their types.
The return type of a method tells what kind of value a method is supposed to return to the point from where it is called.
However, if you use 'void' as the return type of a method, it doesn't need to return anything.
It just performs the work written through the code, and returns the control back to point from where it was called! ;)
+ 6
"Void" means nothing is returned back to the calling method
"Return" means that somthing will be sent back to the calling method
+ 6
How to write methods efficiently
https://www.sololearn.com/post/44876/?ref=app
+ 5
Example: Return Value from Method
class Square {
public static int square() {
// return statement
return 10 * 10;
}
public static void main(String[] args) {
int result;
result = square();
System.out.println(
"Squared value of 10 is: "+ result);
}
}
Use the search bar!
https://www.sololearn.com/post/10362/?ref=app
https://www.sololearn.com/Discuss/1572234/?ref=app
+ 1
Can you give me some example source code?
+ 1
I still don't understand when we should use void or return?
+ 1
Thanks