可能重複:
Where and why JVM checks that the return type of entry method main(String args[]) is void and not anything else?
return type of main in java爲什麼java的主要方法不應該有返回值?
諮詢這兩個問題What's the meaning of the return value of int main(), and how to display it? & What should main() return in C and C++?後,我想出了另一個問題:
爲什麼Java程序的主要方法應返回void,但C/C++程序的主函數應該返回int?
簡而言之,Java程序並沒有結束,因爲'main'方法(運行在主線程上)結束。當所有線程結束時,它結束**。因此對'main'的返回值沒有任何意義。 –