Java Reference
In-Depth Information
of a class are always accessible from all code written in that class re-
gardless of which instance the code is being applied to. We illustrate this
with an example later when we look at how methods can also be used
to control access; see Section 2.6.6 on page 65 .
You should view public and protected members as contractual, because
they can be relied on by code you do not control. Changing them can
be impossible after that code relies on public or protected functional-
ity. Package and private access are part of your implementation, hidden
from outsiders (classes in the same package should be related).
We declared the Body class's fields public because programmers need ac-
cess to them to do the work the class is designed for. In a later version
of the Body class, you will see that such a design is not usually a good
idea.
 
Search WWH ::




Custom Search