search
HomeJavaJavagetting StartedIntroduction to source file declaration rules in java

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment