Reputation: 81
I'm C programmer. I'd like the function main
return a value but apparently main is alway void. Is it true in Java?
Upvotes: 2
Views: 1386
Reputation: 54806
Yes, in Java main is always public static void main(String[] args)
. Why would you want it to return a value anyways? It would just be returning to the enclosing java.exe
process and not to the OS, which isn't very useful.
To exit and return a code to the OS, use System.exit(int code)
.
Upvotes: 4
Reputation: 86774
Use java.lang.System.exit(int status)
to return a non-zero status code.
Upvotes: 3
Reputation: 923
Yes, The "main" function is the start of execution for your program, it's a "special" function which serves as the entry point to the application - you are not supposed to call it from other code and it does not return a value
Upvotes: 0
Reputation: 6919
Main always returns void in Java. If you want your program to return an error value use System.exit()
Upvotes: 17
Reputation: 7951
yes , its true , you should call the function from the main with the class object .. or declare the function as static and call from main to do the work
Upvotes: 0