Home > Java > javaTutorial > body text

In Java, can we define a package after an import statement?

PHPz
Release: 2023-08-26 22:49:06
forward
1005 people have browsed it

In Java, can we define a package after an import statement?

No, we cannot define a package after the import statement in Java. If we try to insert the package after the import statement, the compiler will throw an error. A package is a set of similar types of classes, interfaces and subpackages. To create a class within a package, first declare the package name in the statement in our program.

Example

import java.lang.*;
package test;
public class PackageAfterImportTest {
   public static void main(String args[]) {
      System.out.println("Welcome to Tutorials Point !!!");
   }
}
Copy after login

Output

PackageAfterImportTest.java:3: error: class, interface, or enum expected
package test;
^
1 error
Copy after login

The above is the detailed content of In Java, can we define a package after an import statement?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
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