0
Why do use we void with main() method in java ?
java
3 Answers
+ 4
public static void main(String[] args) {.... your programm .... }
Main method is the entry point of a Java program for the Java Virtual Machine(JVM).
JVM will search for main method which is declared as public, static and void.
main() must be declared public (= access modifier) because as we know it is invoked by JVM whenever the program execution starts and JVM does not belong to our program package.
main() must be declared as static because JVM does not know how to create an object of a class, so it needs a standard way to access the main method which is possible by declaring main() as static. (No need of an instance of an object)
main() must be declared void because JVM is not expecting any value from main(). So,it must be declared as void (=return type)
0
very nice