I have many Java books. They mention the keyword 'return'. But, they do not explain what it does. What does this keyword do and accomplish? What is the point of using it? Thank you.
Printable View
I have many Java books. They mention the keyword 'return'. But, they do not explain what it does. What does this keyword do and accomplish? What is the point of using it? Thank you.
Here's one version of return:
Returning a Value from a Method (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
A return statement returns the information your have in-putted within your method etc... So, when the program is running, if it reaches a return statement then it will complete all the statements within the method.
easily saying, if you make a method "void", no need to use return by the end of the method body, however, if you make a method, such as "int", "String", or "char", you have to assign a return value by the end of the method body, after the keyword "return". for example:
int add(int i, int j) {
return i+j;
}