Thursday, February 23, 2012

Why do we make main function static in JAVA ?

main is the first function to be executed when execution of program starts. In JAVA everything that exists is part of object. main function is declared static so that it can act as class method and can be called without creation of any object. As there are no object when execution has just started so it is required to make it static.

It is convention to make main method public so that it can be assessed from anywhere (Outside class).

Arguments passed in main is String args[] which is actually command line argument and can be passed from command prompt when you run your program using syntax java ProgName ListOfArguments

No comments:

Post a Comment