becoz the main program doesnot return any value to the os.
public static void main
the main function or main method is the first method that gets invoked when you try to run a java application. Any class that has a main method can be executed in a standalone fashion. A typical main method would look like below: public static void main(String[] args) { … // code goes here }
A void method is one that returns no value. The Java main() method is the first method to be called, therefore it doesn't need to return a value to another Java method, therefore it is declared as void. If something needs to be returned to the operating system, this is done differently, not by "returning a value" in the sense of Java.
the main method in java is the client code therefore doesn't return any values Unlike languages like C/C++, the user doesn't specify an error return code by returning from the main method. Instead they should use System.exit(code) to do this. If the Java main method returns, the default code of zero is returned.
// C int main(int argc, char** argv) { return 0; } // Java class MainClass { public static void main(String[] args) { } } Differences: * Java main method must be in a class; C has no class, so no such requirement exists. * Both accept an array of command-line args. * ** Java arrays know how long they are; C does not and thus the main function must have an additional parameter to know the length of the array. * The Java main method has a specific format; the C main function seems to be allowed to differ. * ** The C main function seems to be able to accept different numbers of arguments and have different return types (assuming the implementation allows it).
You can not overwrite a static method in Java,and 'main' is a static method.so,you can't overwrite the 'main'.
The normal exit of program is represented by zero return value. If the code has errors, fault etc., it will be terminated by non-zero value. In C++ language, the main() function can be left without return value. By default, it will return zero. To learn more about data science please visit- Learnbay.co
main() is the function from where the execution starts.
In Java, this keyword is used to specify that the method has no return value.
class Demo { public static void main(String s[]) { System.out.println("hello java frm Demo"); } } class Demo1 { public static void main(String s[]) { System.out.println("hello java frm Demo1"); String z={" "}; Demo.main(); } }
yes it is true becoz the class contain the main function or you can say that it is necessory to define the main function into the class name ex------> class test { int a=10; int b=20; void sum() { int c=a+b; System.out.println(c); } } class test12 { public static void main(String s[]) { test t=new test(); t.sum(); } } in the above example class test12 contain the main function so the file name is as well as test12.java.
void display is the function name in which we want to perform some task or it might be to display something. But it has got its residence in the main() function that means that function's inputs are being supplied from the main(). void doesn't return anything so function call is made in main() which doesn't return anything back to it.