0
What is the need to use return keyword in java? Why using it?
2 Respuestas
+ 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.
+ 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..