Sunday, 6 October 2013

Why main method is static?

This is one of the very popular interview question for beginner. So main method is static because without creating an object you can access this method and start the execution. JVM calls this method by using  its class name dot main method(MyClass.main(params). Now think we don't have main method ,so to do the access we have to create an object,to create an object we have to execute certain required line of code.So without static method entry of an execution is not possible that's why main method is static.

No comments:

Post a Comment