Main method in java:–
Main method in Java is the entry point of the program.The syntax is always public static void main(String args).
public static void main(String args)
- The prototype of main method is predefined but the logic of main function given by user so it is user defined.
- The existence of main method never check the compiler at the time of compilation but execution always start from main method only.
Why main method should be public in java…?
- JVM is responsible to call the main method in java .
- As JVM should call the main method from OS which is present in different package.
So main method should be public in java.
Why main method should be static in java…?
- As JVM is responsible to call the main method only by class name, according to the syntax of JAVA if a member called by class name it should be static in java.So main method should be static in java.
Why main method should be void in java…?
- As main method never returns any value to JVM the return type of main method should be void type.