Monday, July 14, 2008

Why do we need public static void main(String args[]) method in Java

We need
• public: The method can be accessed outside the class / package
• static: You need not have an instance of the class to access the method
• void: Your application need not return a value, as the JVM launcher would return the value when it exits
• main(): This is the entry point for the application

If the main() was not static, you would require an instance of the class in order to execute the method.If this is the case, what would create the instance of the class? What if your class did not have a public constructor?

No comments: