What are access modifiers in Java?

What are access modifiers?

Access modifiers are a tool with which you can customize access to classes, methods, and variables. There are the following modifiers, ordered in ascending order of access:

  1. private – used for methods, fields, and constructors. The access level is only the class within which it is declared.
  2. package-private(default) – can be used for classes. Access only in a specific package (package) in which the class, method, variable, constructor is declared.
  3. protected – same access as package-private + for those classes that inherit from class with modifier protected.
  4. public – also used for classes. Full access throughout the app.
Rate article
ASJAVA.COM
Add a comment

Your email address will not be published. Required fields are marked *

*

code