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.
import java.lang.*; package test; public class PackageAfterImportTest { public static void main(String args[]) { System.out.println("Welcome to Tutorials Point !!!"); } }
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!