File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes why is main method always static?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "why is main method always static??" Watch "why is main method always static??" New topic
Author

why is main method always static??

Ashok George
Ranch Hand

Joined: Mar 25, 2005
Posts: 87
hi all!!
i am very new to java and object oriented programming but studying for SCJP
yesterday while going through an article i was wondering Why is the MAIN METHOD always Static!!!

can any 1 help !!!
Mahesh Rana
Ranch Hand

Joined: Sep 05, 2001
Posts: 139
Take a look at public static void main


SCJP2
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
Java has to call the main method to start your program. If main were not static, java would have to first create an extra instance of the class that contains main. If that class lacks a no-arg constructor, java would have no way to do that.

Keeping main static avoids this complication.


Mike Gershman
SCJP 1.4, SCWCD in process
Ashok George
Ranch Hand

Joined: Mar 25, 2005
Posts: 87
thanx a lot!!!
... thats really helped me in clearing stuff !!!
thanxa lot adios!!! and may god bless u ppl !!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why is main method always static??
 
Similar Threads
Static Variable Problem
main
main method
static variable in static function
R&H Second Edition SampleTestQ#40