
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Can we define a package after the import statement in Java?
No, we cannot define a package after the import statement in Java. The compiler will throw an error if we are trying to insert a package after the import statement. A package is a group of similar types of classes, interfaces, and sub-packages. To create a class inside a package, declare the package name in the first 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
- Related Articles
- Can we write any code after throw statement in Java?
- Difference between import and package in Java?
- Can I define more than one public class in a Java package?
- Why we do not import a package while we use any string function?
- Can we define a static constructor in Java?
- Can I import same package twice? Will JVM load the package twice at runtime?
- How can we import a gson library in JShell in Java 9?\n
- Why do we use import statement in Java? Where it should be included in the class?
- Can we define a class inside a Java interface?
- How to import classes from within another directory/package in Java?
- Can we define an enum inside a class in Java?
- Can we define an enum inside a method in Java?
- How to import Pandas package?
- Is there a need to import Java.lang package while running Java programs?
- Can we define an interface inside a Java class?

Advertisements