Chapter 6
Encapsulating Data and Exposing Methods in Java
It’s time to move past main() methods for writing programs and dig a bit deeper. This step has several elements to it, so I’ve broken the first big step into two chapters. This chapter covers the fundamentals of defining the interface to a class: restricting direct access to member variables and using methods to allow indirect access.
In Chapter 7, “Using Java Methods to Communicate,” I’ll build on this practice by designing methods that express the services a class offers.
In this chapter, we’ll cover the following topics:
- Encapsulating data
- Exposing data through methods
- Applying access modifiers
- Abstracting data
Encapsulating Data
As Chapter 7 will explain, in Java we use methods to ...
Get Java SE 7 Programming Essentials 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.