Comparing C# and Java
Subject:   Minor correction
Date:   2001-06-08 12:39:07
From:   drupp527
On page 2, in the discussion of "The entry point of a public class", the author states "As a comparison, overloading the main method is illegal in Java." This is not quite true.

It *is* true (as I suspect the author intended to explain) that overloaded main() methods in Java cannot be entry points to the class. Only the method with the specific signature "public static void main(String args [])" can serve as the entry point. The specification of the single argument "args" may vary slightly, but it must be of type String[] (an array of Strings). Other definitions of methods named "main" may exist, including those with different visibility levels, parameter lists, and return types. Such methods behave as would comparable methods with other names.

A class is not required to have a "public static void main(...)" method. Such a class is perfectly valid; it just cannot be excercised directly from the command line.

What you can't do in Java is specify two methods with the same name and signature (number, type, and order of arguments) with different return types. I don't have access to a C# compiler, but I suspect this would cause problems in C# as well.