EXPAIN THE REASON FOR EACH KEYWORD OF PUBLIC STATIC VOID MAIN(STRING ARGS[])?

Amit Singh

Total Post:562

Points:2810
Posted by  Amit Singh
Java 
 1391  View(s)
Ratings:
Rate this:
  1. Amit Singh

    Post:562

    Points:2810
    Expain the reason for each keyword of public static void main(String args[])?

    public- main(..) is the first method called by java environment when a program is executed so it has to accessible from java environment. Hence the access specifier has to be public.

    static: Java environment should be able to call this method without creating an instance of the class , so this method must be declared as static.

    void: main does not return anything so the return type must be void

    The argument String indicates the argument type which is given at the command line and arg is an array for string given during command line.

      Modified On Mar-27-2018 12:14:44 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!