wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes public static void main(String args) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "public static void main(String args)" Watch "public static void main(String args)" New topic
Author

public static void main(String args)

Dep Joy
Greenhorn

Joined: May 07, 2003
Posts: 20
As we all know, the entry of a Java class is usually defined as
public static void main(String[] args)
My question is, why the compiler doesn't complain when I defined it as the topic of this message, that is:
public static void main(String args)
Provided a function expects a String array and we give it a String method, it will not compile.
public class Test
{
public static void main(String[] args)
{
CallAFunction("test"); //it won't compile
}
private void CallAFunction(String[] paras)
{
//do sth. here
}
}

Could anybody tell me why, thank you very much!
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
You can legally declare as many main() methods as you want, each with different argument lists, but only the one with (String[]) will be called when you invoke the class from the command line. If it isn't there, you'll get this runtime exception:
Exception in thread "main" java.lang.NoSuchMethodError: main


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Dep Joy
Greenhorn

Joined: May 07, 2003
Posts: 20
It sounds like overloading, I might get it, thanks!
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
It is overloading.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: public static void main(String args)