Types of access modifiers in Java?

Java provides four types of access modifiers to set access levels for classes, variables, methods, and constructors. Following are the access levels -

  • default - Visible to the package. No modifiers are needed.

  • private - Visible to the class only.

  • public - Visible to the world.

  • protected - Visible to the package and all subclasses.