Java-Preliminary Understanding-12th-Object oriented (importing import)

Source: Internet
Author: User

One.

When it comes to finding out, there is not a package, the source of the writing class name to write very long (class name prefix package is many). Class file hierarchy is too many, too many packages, it seems very troublesome.

If you don't want to write such a long name, we have some solutions. We can do this with a keyword so that you can achieve the same functionality.

is to import Demoa package, I think the import means that the location from the other package belongs to the location of the package. This is more convenient to use.

If there are other classes in other packages to use, continue to import them.

Some people say, this is very troublesome, can use simple method, is a wildcard character. All the symbols that match.

Use * to replace all.

Now in the Packa package, the same level has both packages and class files. Now ask, if write import packa.*, can build Demoabc class object?

The answer is no, import imports the classes in the package and does not import the packages in the package. In this way, the sub-package ABC can not be imported, the inside of the demoabc.class can not be imported.

To import the class file of the package in the package, you can write it as follows,

It is not recommended to write the * number when really developing. Because the class file is much more, it is not possible to import all.

The principle of the guide package, which class to use, and which class to import.

So if you use dozens of classes, do you want to import dozens of imports? Yes.

Advanced compiler, without you writing import, a key, it automatically imports all. Hundreds of lines of import statement, it automatically help you to complete. Even if the package does not write, it will automatically help you complete. These are fixed codes that are generated automatically.

There can be only one package in a. java file, but there may be more than one import.

We do not guide the package, the class in the package.

Java-Preliminary Understanding-12th-Object oriented (import imported)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.