View Single Post
Old Jul 23rd, 2006, 1:35 AM   #5
quantalfred
Newbie
 
Join Date: Jan 2005
Posts: 21
Rep Power: 0 quantalfred is on a distinguished road
Quote:
Originally Posted by lectricpharaoh
You can create other versions of main(), with different signatures. However, it is the static one (with a String array as its sole argument) that is called when you 'run' the class. There are two reasons for this.

First, it needs to have the same 'signature', or argument list. This is so the Java VM knows what parameters to use when calling it. Second, and more importantly, it needs to be static so that the VM can call it without first creating any class instances. Non-static methods can only be called using an object of the class. Since the VM won't create classes until you tell it to (barring some startup classes it might create for its own use), you won't have an object to use before main() is called, and thus, it must be a static method.

Having said all that, there is no absolute requirement that a given class have a main() method in the given format, or even a main() method at all. Instead, only the class that is the entry point for your application needs such a method.
Thanks, does that mean, the main function is special in the sense that it can not be called in other class. Or if it can be, how can I do it?
quantalfred is offline   Reply With Quote