A Sdi A Sdi - 1 year ago 153
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
form the method no warning will be shown.
Is it a good practice to do so? Should I keep them public anyways ?

Answer Source

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.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download