• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt

 
bani kaali
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
can anyone pls tell me why we have to declare the main() method as static, taking a string array as an argument?
thanks
bani
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because the Java Language Specification says so.
The method main must be declared public, static, and void. It must accept a single argument that is an array of strings.

[ July 12, 2002: Message edited by: Jessica Sant ]
 
Charu Murali
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A static method is the one that will be called with out craeting any objects. Since we need the main method to be called before any objects are created, it should be decalred as static.

HTH
Charu.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic