When using a class from another package, you can qualify its name with the package name, but this can be tedious.
Full class name qualification becomes cumbersome when packages have deep hierarchies.
To make things easier, the Java language offers the import statement, allowing the use of package classes without requiring complete qualification.
The import statement makes the members of a package visible, allowing them to be used directly.
The general form of the import statement is: import package.classname;.
To import the contents of a package, you can use the import statement with an asterisk (*) to include all classes in the package.
Example of importing a specific class: import mypack.MyClass;.
Example of importing all classes from a package: import mypack.*;.
The import statement must be placed right after the package statement (if any) and before any class definition in the source file.
Using import allows you to give visibility to the bookpack package, facilitating the use of the Book class without requiring full qualification.
To use the Book class, add the import bookpack.* statement; at the beginning of the file.
The above is the detailed content of Importing packages. For more information, please follow other related articles on the PHP Chinese website!