What is the meaning of the "default access specifier" in Java?



Occasionally I may include affiliate links, which means I may get a commision if you purchase something via that link. Check out my privacy policy for more info.

This is my answer to this question on Quora.

There are four access specifiers in Java: public, private, protected, and default. Three of them use their associated word, while default uses none. They appear as follows:

1
2
3
4
5
6
public class JavaApplication {
    Object object1;
    public Object object2;
    private Object object3;
    protected Object object4;
}

“object1” has default access. As others have said, that means that you can only access that feature (be it class, variable, method, etc.) from classes within the same package.

Related posts: