What should the file name match in a Java program?
Understand the Problem
The question is asking what the file name for a Java program should correspond to, specifically whether it should match the package name, import statement, class name, or method name.
Answer
Class name
The file name should match the class name if there is a public class.
Answer for screen readers
The file name should match the class name if there is a public class.
More Information
In Java, if you have a public class in your file, the file name must match this class name exactly. This is necessary for proper compilation and execution.
Tips
Not matching the file and class names when a public class is present will result in a compilation error.
Sources
- Myth about the file name and class name in Java - GeeksforGeeks - geeksforgeeks.org
- Why does Java filename and classname should be the same? - Quora - quora.com