Java Reference
In-Depth Information
Call this file BookDemo.java and put it in a directory called bookpack .
Next, compile the file. You can do this by specifying
from the directory directly above bookpack . Then try executing the class, using the fol-
lowing command line:
Remember, you will need to be in the directory above bookpack when you execute this
command. (Or, use one of the other two options described in the preceding section to spe-
cify the path to bookpack .)
As explained, BookDemo and Book are now part of the package bookpack . This means
that BookDemo cannot be executed by itself. That is, you cannot use this command line:
Instead, BookDemo must be qualified with its package name.
Packages and Member Access
The preceding chapters have introduced the fundamentals of access control, including the
private and public modifiers, but they have not told the entire story. The reason for this is
that packages also participate in Java's access control mechanism, and a complete discus-
sion had to wait until packages were covered.
The visibility of an element is determined by its access specification— private , public ,
protected , or default—and the package in which it resides. Thus, the visibility of an ele-
ment is determined by its visibility within a class and its visibility within a package. This
multilayered approach to access control supports a rich assortment of access privileges.
Table 8-1 summarizes the various access levels. Let's examine each access option individu-
ally.
Search WWH ::




Custom Search