In the design of programs such as libraries, only part of the code is published to the user. This can be achieved through access control.
The "library" is composed of a "package" and is packaged with "package" (This sentence must be in the first line without comments ), the user can use "import" to introduce it. When encapsulating a package, use the unique identifier of the Reverse Domain Name to indicate a package (because the domain name is unique, the package name issued is also unique ). During execution, the Java interpreter first finds "classpath" and uses this as the root directory to find the ". Class" file.
Only one "Access Controller" in Java is special: if nothing is written before a variable (that is, the default value), it indicates that the variable is a "package" access permission. The usage of "private" is as follows, so that the object "new" is not so casual.
Class sundae {
Private sundae (){}
Static sundae makeasundae (){
Return new sundae ();
}
}
Public class test {
Public static void main (string [] ARGs ){
//! Sundae x = new sundae ();
Sundae x = sundae. makeasundae ();
}
}