Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Why main() method is static

807591Jun 20 2008 — edited Jun 20 2008
By defining main() method as static, JVM can invoke it without creating object for the enclosing class. But, JVM can create an object for the corresponding class and can invoke the main method then? Is there any strong reason for this?

The reason I got when searched on Internet says "JVM can not create any object before program runs. So, to run the program main should be invoked without creating any object. That's why main should be static."

But, I'm thinking that when JVM can load a class, why it can not create object before calling main method? after all JVM only creates and maintains all objects in our program.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 18 2008
Added on Jun 20 2008
3 comments
473 views