Junior — Middle
How to declare the default access level in Java?
sobes.tech AI
Answer from AI
In Java, if the access modifier is not explicitly specified for a class, method, or field, the default is package-private access level. This means that the element is accessible only within the same package.
Example:
class MyClass { // package-private class
void myMethod() { // package-private method
// code
}
}
Here, MyClass and myMethod are accessible only to classes within the same package where they are declared.