Access modifier in java
1. default
2. private
3. protected
4. public
2. private
3. protected
4. public
1.default:-
-If you dont define any access modifier for any method in java then that method will access within same package classes defined under the package.
- if try to access method outside the package you will get error.
Note:- if class is public but method is default then again you will get error.
Note if class is not public but method is public again you will get error at package import in another package.
2.private :- private access modifier method or variable accessed within the class.If you try to access method out the class the class you will get error .
even the class in same package.
you can not declare a class private .you will get error.
3.protected method you cant access outside the package. You will get protected method access within the same package classes .
Note:- If you want to access protected method in another package then
extends another package class with method class name which contain protected method.
then create the object of current class and call protected method .
Public :- accessible every where no rstriction.