Access Modifiers - Java File Requirements Continued
Java File Requirements
Now that we know about access modifiers, it's important to understand how they relate to Java file naming conventions. Here are the key rules:
- If a Java file contains a public class, the file name must match the class name exactly (including case) and have a .java extension.
MyClass.java
- A Java file can contain multiple classes, but only one of them can be declared as public. The public class must be the one that matches the file name.
MyClass.java
- If a Java file does not contain any public classes, it can have any name, but it's still a good practice to name the file after one of the classes it contains for clarity.
ByteBrawl
0