+ 1
Why is the main method void?
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.
+ 3
Because it does not return anything.
+ 1
when will it return something?
+ 1
main method cannot return, I think.
Other methods can use the return statement.
Complete the Java Course for more info.