What is Void Main in Java ?
Void Main in Java
- Public- It is access specifier means from every where we can access it. static - access modifier means we can call this method directly using class name without creating an object of it.
- void - is a return type. main - method name. string [] args - in java accept only string type of argument and stores.
- The void keyword denotes that a method does not have a return type. However, even though a constructor method can never have a return type, it does not have the void keyword in its declaration.
Examples:
- The method displayBookData() does not have a return type as shown by the use of the void keyword. Note that the constructor method Book(String, String, String) does not use the void keyword even though it too does not have a return type.
What is the Use of Void in Java ?
- The keyword static allows main( ) to be called without having to instantiate a particular instance of the class.
- This is necessary since main( ) is called by the Javainterpreter before any objects are made. The keyword void simply tells the compiler that main( ) does not return a value.