We've all come across a single source file that has multiple Java classes, but when the first class uses the public modifier, the following class uses the public modifier to make an Error. This means that a Java source file can have at most one public class.
When there is a public class, the source file name must be identical, otherwise it cannot be compiled, and if there is no public class in the source file, there is no consistency requirement in the file name and class.
The Java Virtual machine instance runs a Java program by calling main () of a class, and this main () must be public static void and receive an array of strings as a parameter, and any class that has such a main () can be the starting point for the Java Program. This main method must be in the class declared by Public. Public is used to differentiate the main class in the source file, and if there are multiple, the Java virtual Opportunity cannot find the program Entry.
Why there is only one public class in a Java source File.