Can anyone explain What are access modifiers in java in easy language ? With examples ?
Asked
Active
Viewed 97 times
-4
-
https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html – JB Nizet Nov 11 '18 at 08:40
-
You are expected to do serious research prior posting questions here. Please remember that before posting another question. Especially given the fact that you are asking something that has been documented zillions and zillions of times. – GhostCat Nov 11 '18 at 08:41
1 Answers
0
Access modifiers are keywords that set the accessibility of class, interface, variable, data member, method or constructor and their setters. They are also known as visibility modifier. Access modifiers gives a better encapsulation to your code. You can control what part of a program can access the members of a class. So that misuse of data can be prevented.
- Private - Declarations are visible within the class only
- Default - Declarations are visible only within the package (package private)
- Protected - Declarations are visible within the package or and all sub classes
- Public - Declarations are visible everywhere

Sandeepa
- 3,457
- 5
- 25
- 41