[java] Can a java file have more than one class?

What is the purpose of having more than one class in a Java file ? I am new to Java.

Edited: That can be achieved by creating a inner class inside a public class, right?

This question is related to java class

The answer is

Yes, it can. However, there can only be one public top-level class per .java file, and public top-level classes must have the same name as the source file.

The purpose of including multiple classes in one source file is to bundle related support functionality (internal data structures, support classes, etc) together with the main public class. Note that it is always OK not to do this--the only effect is on the readability (or not) of your code.

Similar questions with java tag:

Similar questions with class tag: