Home > Java > Javagetting Started > How to use import to import custom packages in java

How to use import to import custom packages in java

王林
Release: 2020-06-11 13:14:40
Original
6774 people have browsed it

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) {
        
        }
}
Copy after login

Or you can use. * means wildcard, that is, import all classes in the package.

Such as:

import animals.*;
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template