+ 2

what is return(); statement? Where should we use it? How it is useful to our program?

23rd Jul 2016, 4:40 PM
Dhana sri sowmya avidi
Dhana sri sowmya avidi - avatar
4 Answers
+ 1
when u work with methods some of them will return result and u use: return resultVariable; statment to break from function and return result to caller... This is if method returns unique result, and dataType of return is predefined in name of method like: public String method(){ String name; //code return name; } if method return type is void return statment can't be used because caller don't expect any return...
23rd Jul 2016, 4:50 PM
Petar Suvajac
Petar Suvajac - avatar
0
If you return from a method, it returns control to its calling function which might also return a value if the method your returning from was defined as to return a value, if you return from main you return control back to the OS including a return code usefully 0 if you program ran successfully or returns an error or exit code if your program terminated abnormally usually -1
25th Jul 2016, 1:13 AM
Eric Gitangu
Eric Gitangu - avatar
0
Just a slight variation from Petars answer, you can return from a void function, you will not be returning a result but rather you'd be returning to the calling function, any code after a plain return; will not be executed.
25th Jul 2016, 6:14 PM
Eric Gitangu
Eric Gitangu - avatar
- 1
thank you.
25th Jul 2016, 4:05 PM
Dhana sri sowmya avidi
Dhana sri sowmya avidi - avatar