next up previous
Next: Instance variables Up: Unit 03 Previous: Controlling the access to

Rules for accessing the fields of a class

Typically, the access to the fields of a class is done as follows:

In this way, the methods that correspond to functionalities of interest for the clients are visible to the outside the class, while the instance variables and the auxiliary methods that are needed to support those functionalities, but that are not of interest for the clients, are visible only inside the class.

The set of public fields of a class is called the public interface of the class.

Note: In Java, there are two additional access modalities, namely protected and ``visible in the package'' (the latter is obtained by omitting the access modifier). These will not be discussed in this course, but will be dealt with in subsequent programming courses.


next up previous
Next: Instance variables Up: Unit 03 Previous: Controlling the access to