MY mENU


Thursday, 9 February 2012

Why main() is static in java

In java the program execution begins with the main() method. So it must be called before any object exist.As main() is static it is independent of any object.


Why we use main() method in java programme


Jvm needs a default method to start program and from that method it starts instantiating the objects of other classes. so if every one uses their own methods then jvm is not able to find from where it need to start compiling. so Java people kept a default method not main() method, it is argumented main ie "main(String var[])" and this shoubld be always public and static. so that it is visible to the jvm.

No comments:

Post a Comment