Total Pageviews

Saturday, 23 January 2016

Why is main method public static and void in Java?

Java program’s main method has to be declared static because keyword static allows main to be called without creating an object of the class in which the mainmethod is defined. If we omitstatickeyword before main Java program will successfully compile but it won’t execute.
For a little detailed description, look at the usual signature of Java’s mainmethod
public static void main (String[] args)
Above code line begins defining the main method. This is the line at which the program will start executing. All Java applications begin execution by calling main.

No comments: