Home  >  Article  >  Java  >  How to use import to import custom packages in java

How to use import to import custom packages in java

王林
王林Original
2020-06-11 13:14:406573browse

How to use import to import custom packages in java

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:

How to use import to import custom packages in java

(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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn