The error I get is exactly the error specified in:
http://java.syntaxerrors.info/index.php?title=Own_file
(class must be defined in its own file.)
but they don’t give a solution there how to solve it, other than just having a file per public class.
Thank you, eclipse, for making me do this, but this is not mandatory in Java. Is there a way to get rid of this error?
Yes, it is mandatory in Java. Each public class has to be in a separate file named exactly the same way as the class.
See this question about it. The Java language specification writes that this is not 100% mandatory for compilers, but they usually do that. And since it is a good thing, and is noted in the spec, all compilers do it.
If you want to have multiple classes in the same file, that’s a different story. You can do it in two ways:
class Fooafter the body of the main class. You can have any number of non-public classes in the same filepublic static class InnerFooinside the main class body. That way they will be visible to other classes byFooClass.InnerFoo