What is the default access modifier for a class member in Java?

The story behind the answer

The default access modifier for a class member in Java is package-private.

A member is package-private when its declaration uses no access-modifier keyword. Such a field, method, constructor, or nested type can be accessed by code in the same package, but not generally by code in unrelated packages. Java also calls this “default access,” although default is not itself a keyword.

Package-private access sits between private and protected in everyday visibility. Private members are restricted to their top-level class, while protected members are available within the package and under specific inheritance rules outside it. Public members are broadly accessible, subject to module and package-export rules in modern Java.

A common mix-up is assuming class members default to public, as they do in some beginner examples or interface declarations. Interface members are a special case: fields are implicitly public, static, and final, while interface methods have their own rules. For ordinary class members, omitting a modifier means package-private access.

Source: Wikipedia · fact-checked Aug. 2026

Add question to a list

Choose a list to keep this question in: