Java Default Access Modifier Example



Java default access modifier example demonstrates how to control the visibility of a field, method, class, and constructor using default access modifier.

Java Default Access Modifier

When we do not mention any access modifier, it is called the default access modifier. The scope of this modifier is limited to the package only. This means that if we have a class with the default access modifier in a package, only those classes that are in this package can access this class. No other class outside this package can access this class. Similarly, if we have a default method or data member in a class, it would not be visible in the class of another package.

Java Default Access Modifier Example

Below diagram demonstrates the example of default access modifier and it's visibility:

Comments