Why is main() method public static void in Java?
Why is main() method public static void in Java?
public:
The main method must be accessible from anywhere because it is called by the Java Virtual Machine (JVM) to start your program. If it wasn’t public, the JVM wouldn't be able to access it.static:
The JVM calls the main method without creating an object of the class. Declaring it static means the method belongs to the class itself, not to any object. So, the JVM can run it directly.void:
The main method does not return any value to the JVM, so its return type is void.
In short:
public → JVM can call it from anywhere.
static → JVM can run it without creating an object.
void → It doesn’t return any value.