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



This site utilizes Google Analytics, Google AdSense, as well as participates in affiliate partnerships with various companies including Amazon. Please view the privacy policy for more details.

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.

Leave a Reply

Note that comments won't appear until approved.