file name in java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

file name in java

why public classes must be same with the file name ? and classes with default access modifiers ( package ) dont need to be same with file name?

28th Jul 2018, 8:46 AM
Mohammad Nasrollahi
Mohammad Nasrollahi - avatar
1 Answer
+ 1
https://www.quora.com/Why-does-java-file-name-must-be-same-as-public-class-name this will be of some help. In short, it's a standard, and one that helps programs find the correct class files. Because public classes are intended to be used/found by other classes this helps speed up the process. I believe that even when you have multiple classes in a file, or nested/inner classes they are all essentially treated as separate classes, "top level" classes don't really mean anything in the compiled code
28th Jul 2018, 11:16 AM
Dan Walker
Dan Walker - avatar