Originally posted by ashok reddy devaram:
... The main thing is when u have a public Access modifier infron of a class then u must write the "main()" method in that class only...
Well, if you have a top-level class or interface that's declared public in a
Java file, then the file must share that same name, so you would
compile using that file name.
However, any class can contain a main method. And once you have your class files compiled, you can
run whichever you choose.
For example, the following can be saved in a single file called TestA.java...
You would compile with
javac TestA.java, because that's the name of the file. But both of these classes have main methods, so once compiled, you can run either
java TestA or
java TestB.