Understanding the relationship between void and main in Java public static void main (String[]args)

Asked 2 months ago, Updated 2 months ago, 1 views

I'm a beginner in programming.

When you start studying Java, the first sentence you see is public static void main (String[]args), but you don't understand why you use the main method that does not return the return value and the return statement at the same time.

I would appreciate it if you could let me know.

java

2022-09-30 13:45

3 Answers

public static void main(String[]) cannot return a value with return.Writing such code results in a compilation error.

If there is such a code in any reference document, it may be a document error or misreading.


2022-09-30 13:45


when return value is required int main(...)

using

if no return value is required void main(...)
That's all I have to say

In , you cannot use these two at the same time.

Is it okay to say #?


2022-09-30 13:45

For your information, if you want to return the results to the operating system in main, you can use System.exit; to complete the process to determine whether the operating system is successful or abnormal.


2022-09-30 13:45

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.