Hi Guys: The class in a file that has the main() method: Is it required to be public and only public in that file? I thought so all along the way but then I saw code that had no public class and it still runs.... Thanks Barkat
In each Source File there can be one and Only One public class which hosts the main method.Thats the only way the runtime System and statrt working on your program. There is no way a program w/o a public class can execute.is so can u please paste that code here. Hope this helps. Gowri
Joined: Jun 06, 2002
A source file can have any number of top-level classes, but at most one of them can be public. If there is a public class, its name must match the name of the file. Any class, public or not, can have a method with the signature public static void main (String args) and if you feed such a class to the java interpreter, that method will execute.
Joined: Aug 03, 2002
There is no way a program w/o a public class can execute.
Hi Whiz, Question is why the code I posted before works fine. Thanks.