0

What is the need to use return keyword in java? Why using it?

11th Apr 2020, 7:05 AM
Shankar Devaraju
Shankar Devaraju - avatar
2 Answers
+ 1
1. in main method/function, it is like an end statement which ends the programs execution. 2. in other methods/functions, the return statement returns a value based on the given parameters. 3. You can also return different values for problems such as 0 for success and 1 for error. Note: a return statement can only be used if your method/function is no of type VOID.
11th Apr 2020, 7:24 AM
RinasSam
RinasSam - avatar
+ 1
In java, main method is (strictly) not required return statement since it must be void.. It only required when method return type otherthan void, must return needed return value.. Else put just void as return type.. There is no concept of success or failure to tell os in java. It is in c/c++ not in java since everything handle by JVM..
11th Apr 2020, 8:20 AM
Jayakrishna 🇼🇳