The inheritance of member variables and member methods is related to the access controllers of members. The access controllers determine whether child classes can inherit members of the parent class.
The access control operator is also related to another concept, namely the package ).
1. What is a package?
In a simple understanding, a package is a classification of classes. It is convenient to put function-related classes in the same package for mutual access.
For example, the previously introduced string belongs to the java. lang Package, and Java. Lang is the package name. Many basic classes are included in this package, including the object class described above.
For example, java. util. date is the package name, and date is the class name. Java. util is a toolkit. To learn Java, classes in this package should be very familiar.
When accessing a class, you must specify the package name. Sometimes it is called "full class name" or "full class name", which means the class name containing the package name.
Different packages can have the same class, and different classes can be distinguished by the package name. For example, java. SQL. Date and Java. util. date indicate the date class.
2. Package Definition
Use package to define a package, for example:
Package ch12;
The package name can also be composed of multiple parts, separated by ".". For example:
Package ch12.test;
The components of a package should be as meaningful as possible. For some common components, we should try to keep the package unique throughout the world when naming the package. Therefore, the package name usually contains a wealth of information, for example, the country logo, company type, company name, project name, etc. For example:
Com. MySQL. JDBC
CN. Neusoft. UFS. Common
Note: The package Declaration must be the first line in the Java file. The following code is incorrect.
Import java. util .*;
Package ch12;
Public class mytest {
...
}
3. Package reference
When you want to use another class in a class, you need to declare this class and declare it through import. If the class to be accessed is in the same package as the current class, you do not need to introduce it. See the following code:
Package CH11;
Public Class {
...
}
Package ch12;
Public Class B {
...
}
Package ch12;
Import ch11.a;
Public class c {
Private;
Private B;
...
}
In Class C, Class A and Class B are required. Because Class A and the current class C are in different packages, Class A needs to be introduced, and class B and class C are in the same package, so you don't need to introduce it.
Is there a relationship between CH11, ch11.action, and ch11.common? Remember: there is no relationship between these packages.
For more information about the impact of the package on the access to classes and members, see.
Last time: 33rd parent class and inheritance next time: 35th access permission Li xucheng csdn blog: Login? U= 124362 & C = 7be8ba2b6f3b6cc5