2.19.3 Rules of Thumb2.19.2 Field and Method Visibility2.19 Visibility Modifiers2.20 The Applet Class Revisited

2.19.3 Rules of Thumb

The details of field visibility can become quite confusing; here are some simple rule of thumbs that are typically used:

Thus a typical class is structured as follows:

   // class can be used by any other class
   public class Class
   {
     // the private fields
     private type field;

     // the public constructors
     public Class (...) { ... }

     // the public methods for the user
     public type method (...) { ... }

     // the private (or private protected) methods for the class
     private type method (...) { ... }
   }

Only in special situations one might want to use protected to expose some basically private methods to other classes within the current package.


© Wolfgang Schreiner; February 3, 2005

2.19.3 Rules of Thumb2.19.2 Field and Method Visibility2.19 Visibility Modifiers2.20 The Applet Class Revisited