What should be public? What should be private?

 

As a rule of thumb:
  • Classes are public.
  • Fields are private.
  • Constructors are public.
  • Getter and setter methods are public.
  • Other methods must be decided on a case-by-case basis.
All of these rules may be freely violated if you have a reason for doing so. These are simply the defaults that handle 90% of the cases.

List | Previous