True, you can only have one public class per file. What you need to do is put all your public classes each in their own file, the name of which should be identical to the name of the class. Make sure they are also in the same directory, and that the package name is the same in each. Here's an example that I hope will help.
// My first class:
package
test;
public class Test1 {
public Test1() {
super();
System.out.println("hi, I'm test 1");
}
public static void main(
String[] args) {
Test1 one = new Test1();
Test2 two = new Test2();
}
}
// My second class:
package test;
public class Test2 {
public Test2() {
super();
System.out.println("Hi, I'm Test2");
}
}
These files would need to be in a directory named "test", because the directory name must match the package name, which in the case of these two classes is test. (If the package were "package test.foo", the directory would need to be {your-root}\test\foo\Test.java)
Then, from the command line you can compile and run these classes.
(My files are both in C:\home\examples\java\test)
compile any files ending with the java extension:
C:\home\examples\java>javac .\test\*.java
run the class test.Test1 (test is the package, Test1 the class)
-cp . means that your classpath is set to the directory you are in, so when you specify package test, class Test1, it will look for the compiled Test1.class file in {your-current-directory}\test\Test1.class
C:\home\examples\java>java -cp . test.Test1
hi, I'm test 1
Hi, I'm Test2
C:\home\examplesjava>
Hope this helps. let me know if it doesn't, or you have any questions.