Understanding access control
One significant and invaluable feature of OOP is access control. If you have already worked with an OO language, then you may be familiar with this concept; if not, let me explain what access control means.
Access control in Java concerns the visibility of classes, fields, and methods to other classes. You must have sufficient access to create objects and access fields and methods in a class.
Access control, in other languages, may imply a security mechanism that can ensure that a request for access to a method–for example–is coming from an authenticated user. This is not what Java does; in Java, it is about how objects can interact with each other.
Let’s look at the options for visibility; the first will be Java packages.
Packages
The first piece of the access control puzzle is the Java package and its corresponding import
statement. In Chapter 3, The Maven Build Tool, we learned about Java packages and how they are...