+ 1

Why is the main method void?

16th Aug 2017, 3:30 PM
GodBlessAmericasFrog
GodBlessAmericasFrog - avatar
4 Respostas
+ 4
The program stops when all threads stop (Assuming they aren't 'daemon'). Daemon meaning the program will exit even if the thread is still running. So, because of threads the program may not end right when the main method is finished. Think of it this way: C++ returns an int to see if the program ran successfully. Yet if Java had returned an int the program can still fail, even if it had returned 'successful'. Note that C and C++ were created before multi-threading became a common thing. @Amrit In regards to your 2nd post, Main method is just a method, it can do anything another method can. Just use an empty return statement, like: "return;" to terminate a void method early.
16th Aug 2017, 4:06 PM
Rrestoring faith
Rrestoring faith - avatar
+ 3
Because it does not return anything.
16th Aug 2017, 3:38 PM
Dragon Slayer Xavier
Dragon Slayer Xavier - avatar
+ 1
when will it return something?
16th Aug 2017, 3:39 PM
GodBlessAmericasFrog
GodBlessAmericasFrog - avatar
+ 1
main method cannot return, I think. Other methods can use the return statement. Complete the Java Course for more info.
16th Aug 2017, 3:40 PM
Dragon Slayer Xavier
Dragon Slayer Xavier - avatar