The following is a java4android video tutorial from marschen.
Main content.
1. Access Permissions in Java
2. Import the Software Package
Access permission in Java
1. Public Permissions
2. Private permission
3. Default package-level access permissions
4. Protected is protected.
Instance description.
Package Org. marsdroid; // The public class can be modified. The member variables and member functions // public have no restrictions. In the same package, or classes in different packages can be freely accessed. // Private can modify member variables and member functions. // Private can only be used in this class. // default (no permission modifier is written, is the default permission) can modify the class, member variables and member functions // default in the same package, can be freely accessed. // public class // If a class is declared as public, the class name must be the same as the source file name. is this Java syntax? // Effect of public (cross-package access) // if the class is not public, it cannot be accessed from the external package. (that is, two classes are not in the same package) // two classes are in different packages. One Class calls the other, the class must be public // two classes in different packages. If you want to access a member function of a class, member function, and member variable, then these member functions, the member variable also requires publicpublic class person {public string name; Public int age; // public void introduce () {system. out. println ("name") ;}// private variable, which can only be used in the current class, regardless of whether the two classes are in a file. // Private function, which can only be used in the current class, no matter whether these two classes are not in the same file/private class, I will talk about it later. // default permission. By default, nothing is written. // default if person and test are in the same package, test can call the variables and functions of the person class. // default if person and test are not in the same package, test cannot call the variables and functions of the person class. // default indicates the package access permission.
Package COM. marsdroid; import Org. marsdroid. person; // if multiple packages need to be imported, use the wildcard Number * // import ort. marsdroid. *; Class test {public static void main (string ARGs []) {// because person and test are not in a package, the full name of person must be written. // Org. marsdroid. person P = new Org. marsdroid. person (); person P = new person (); // import Org. marsdroid. person, you can directly write p. name = "zhangsan"; p. age = 10 ;}}