F.3 Controlling Access to Members
The access modifiers public
and private
control access to a class’s variables and methods. In Appendix G, we’ll introduce the access modifier protected
. As you know, the primary purpose of public
methods is to present to the class’s clients a view of the services the class provides (the class’s public
interface). Clients need not be concerned with how the class accomplishes its tasks. For this reason, the class’s private
variables and private
methods (i.e., its implementation details) are not accessible to its clients.
Figure F.3 demonstrates that private
class members are not accessible outside the class. Lines 9–11 attempt to access directly the private
instance variables hour
, minute
and second
of the Time1 ...
Get Android How to Program, 3/e now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.