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 immediately 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.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3