-
Notifications
You must be signed in to change notification settings - Fork 0
Access Control
#1. Introduction The levels of access control from “most access” to “least access” are public, protected, package access (which has no keyword), and private, then how the components in the lib are bundled together into a cohesive library unit? This is controlled with the package keyword in Java, and the access specifiers are affected by whether a class is in the same package or in a separate package.
#2. Package: the lib unit A package contains a group of classes, under the same namespace. for example, there is a utility lib in java organized under the namespace java.util; and one of the classes is ArrayList, One way to use an ArrayList is to specify the full name java.util.ArrayList.
java.util.ArrayList list = new java.util.ArrayList();
if the import keyword is used to import the lib, you can name that class in the import statement, so you can make the above shorter:
import java.util.ArrayList;
ArrayList list = new java.util.ArrayList();
When you create a source-code file for Java, it’s commonly called a compilation unit. Each compilation unit must have a name ending in .java, and inside the compilation unit there can be a public class that must have the same name as the file (including capitalization). There can be only one public class in each compilation unit; otherwise, the compiler will complain. If there are additional classes in that compilation unit, they are hidden from the world outside that package because they’re not public, and they comprise “support” classes for the main public class.