What are the access modifiers in Java?
| Modifier | Same class | Same package | Subclass | Other packages |
|---|---|---|---|---|
| private | yes | no | no | no |
| default (no word) | yes | yes | no | no |
| protected | yes | yes | yes | no |
| public | yes | yes | yes | yes |
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. |