+ 2
what is return(); statement? Where should we use it? How it is useful to our program?
4 Réponses
+ 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...
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
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.
- 1
thank you.