Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the concept and usage of package in Java

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Most people do not understand the knowledge points of this article "what is the concept and usage of package in Java", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "what is the concept and usage of package in Java" article.

A little bit of eye contact

1. The declaration method of package:

Package package name [.package name 2.package name 3]

The import method of package 2 is as follows:

Import package package name. Class name

3 if there are hundreds of classes in a project, it will be troublesome to import one by one. In order to facilitate the import, you can use the form of "package name. *", for example:

Import java.io.*

The "*" here is a wildcard character that indicates "all" subclasses under the "java.io".

It is important to note that even if the format used is "package. *", it does not mean that all classes in this package are imported. The Java compiler is very smart. It will "import on demand". Java will not load any classes that are not needed in the code.

Second actual combat

1 the structure of the code

2 code

Person.java

Package demo.java.a; / / declare the methods in the pakagepublic class Person {public String talk () / / class {return "Person-- > > talk ()"; / / return a string}}

TestPackage.java

Package demo.java.b;import demo.java.a.Person;// imports the Person class from the demo.java.a package into this package class TestPackage {public static void main (String [] args) {/ / calls the method in demo.java.an and outputs System.out.println (new Person (). Talk ());}}

3 run

Person-> > talk ()

The above is the content of this article on "what is the concept and usage of package in Java". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report