+ 1

What is method return value?

28th Nov 2018, 10:50 PM
Dina Noviana
7 Answers
+ 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! ;)
28th Nov 2018, 11:13 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 6
"Void" means nothing is returned back to the calling method "Return" means that somthing will be sent back to the calling method
28th Nov 2018, 10:54 PM
D_Stark
D_Stark - avatar
+ 6
How to write methods efficiently https://www.sololearn.com/post/44876/?ref=app
29th Nov 2018, 11:35 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 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
28th Nov 2018, 11:06 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 1
Can you give me some example source code?
28th Nov 2018, 10:55 PM
Dina Noviana
+ 1
I still don't understand when we should use void or return?
28th Nov 2018, 10:56 PM
Dina Noviana
+ 1
Thanks
28th Nov 2018, 11:13 PM
Dina Noviana