What are the access modifiers in Java?

ModifierSame classSame packageSubclassOther packages
privateyesnonono
default (no word)yesyesnono
protectedyesyesyesno
publicyesyesyesyes

Use the most restricted level which works. Fields are usually private, and the methods which others must use are public. See Encapsulation.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.