Access specifiers in java

Access level modifiers determine whether other classes can use a particular field or invoke a particular method


There are four types of access modifiers

1.     public

2.     protected

3.     default or package or no modifiers

4.     private



                Can be accessed anywhere from an application


                Can be accessed within the class as well as inherited class from different package.

No modifiers

                Can be accessed only within the same package.


                Can be access only within the same class.


Refer below diagram for details.


In class you can use public or no modifiers

whereas member variable, methods, constructor can use all the four access modifiers.

By default constructor will use the same modifiers mentioned in class

Related Post