Introduction to source file declaration rules in java

王林
Release: 2020-05-20 17:15:47
Original
2791 people have browsed it

Introduction to source file declaration rules in java

When we define multiple classes in a source file and there are import statements and package statements, we must pay special attention to the following rules.

1. There can be only one public class in a source file, and there can be multiple non-public classes in a source file;

2. The name of the source file should be the same as the class name of the public class. Keep it consistent;

(Video tutorial recommendation:java video)

For example: the class name of the public class in the source file is People, then the source file should be named People. java.

3. If a class is defined in a package, the package statement should be on the first line of the source file;

4. If the source file contains an import statement, it should be placed in the package statement. and class definition. If there is no package statement, the import statement should be in the first line of the source file;

5. The import statement and package statement are valid for all classes defined in the source file;

6. In the same source file, different package declarations cannot be given to different classes.

Recommended tutorial:Getting started with java development

The above is the detailed content of Introduction to source file declaration rules 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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!