Java Programming/Keywords/public

is a Java keyword which declares a member's access as public. Public members are visible to all other classes. This means that any other class can access a field or method. Further, other classes can modify fields unless the field is declared as.

A best practice is to give fields access and reserve  access to only the set of methods and  fields that define the class' public constants. This helps with encapsulation and information hiding, since it allows you to change the implementation of a class without affecting the consumers who use only the public API of the class.

Below is an example of an immutable class named   which maintains  instance fields named   and   but provides a  constructor and two  accessor methods.