Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why is main method always static??

 
Ashok George
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at public static void main
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ashok George
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx a lot!!!
... thats really helped me in clearing stuff !!!
thanxa lot adios!!! and may god bless u ppl !!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic