A class that is declared without any access modifiers is said to have package access. This means that the class can only be accessed by other classes and interfaces that are defined within the same package.
If a class in Java is declared without any access modifiers, it will have package-private (also known as default) access. This means that the class can be accessed only within the same package. It cannot be accessed from outside the package in which it is declared.
Here’s a breakdown of the access modifiers in Java:
- Public: Accessible from anywhere. No restrictions.
- Protected: Accessible within the same package and by subclasses (even if they are in a different package).
- Default (Package-Private): Accessible only within the same package. If no access modifier is specified, this is the default.
- Private: Accessible only within the same class.
So, if a class is declared without an access modifier, it defaults to package-private access.