+ 2
My question is why void is used with main in public static void main(String ab[])?
4 Answers
+ 7
void means empty
Here void is return type
In java,main function doesn't return anything
Hence we use void with main @Shubham Agarwal
+ 3
I assume you're asking why it's void instead of int like in C++.
The main may not be the last method run due to the introduction of multi-threading. This would defeat the purpose of returning something with main.
I'm not sure if threads in C++ are force stopped before the main or not, but I'm pretty sure that's why Java devs decided to stick with void and not return anything rather than int.
+ 2
Since it is the main loop of the program, it doesn't have a return value, so it's void. When the main loop is done, the program simply ends.
0
thnxx I also understand