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

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

PHPz
Release: 2023-08-26 22:49:06
forward
1058 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
Latest Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template