The prerequisite for using import to import a custom package in Java is that it must be under the same project in Java, so that the required package classes can be imported across packages.
The way to use import to import a custom package in java is: [import package name.class name].
For example, there is now a project directory as follows:
(Video tutorial recommendation: java video tutorial)
There are two classes under the animals package, one is Animal and the other is MammalInt class. Assuming that the Array class wants to reference a class in the animals package, how should it be imported:
import animals.Animal; //采用class来定义类的名称 //Array类的名称 public class Array { public static void main(String[] args) { } }
Or you can use. * means wildcard, that is, import all classes in the package.
Such as:
import animals.*;
Recommended tutorial: java entry program
The above is the detailed content of How to use import to import custom packages in java. For more information, please follow other related articles on the PHP Chinese website!