A Sdi A Sdi - 24 days ago 24
Java Question

Package local access

In IDE Some public methods are marked with a warning as

Access can be package local
and if I remove
public
form the method no warning will be shown.
Is it a good practice to do so? Should I keep them public anyways ?

Answer

If the method is only accessed within the package, the best practice is to use the "default" access modifier (by not specifying any access modifier). Further more briefly here are the four access modifiers used in Java and there accessibility 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.
Comments