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

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

PHPz
PHPzforward
2023-08-26 22:49:06964browse

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 !!!");
   }
}

Output

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

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete