
- 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
How to use classes in other package in Java
You can understand it using an example where a Boss class is defined in payroll package.
package payroll; public class Boss { public void payEmployee(Employee e) { e.mailCheck(); } }
if the Employee class is not in the payroll package? The Boss class must then use one of the following techniques for referring to a class in a different package.
- The fully qualified name of the class can be used. For example −
payroll.Employee
- The package can be imported using the import keyword and the wildcard (*). For example −
import payroll.*;
- The class itself can be imported using the import keyword. For example −
import payroll.Employee;
- Related Articles
- How to put two public classes in a Java package.
- How to use sub-package in Java?
- How to import classes from within another directory/package in Java?
- Accessing a Java class in other package.
- How to load classes at runtime from a folder or Java package
- How to use enums in Python classes?
- How to access Java package from another package
- How to use the Time package in Lua programming?
- How to use functions from another package in Golang?
- How to import all classes in Java?
- How can we use a diamond operator with anonymous classes in Java 9?
- How to find package explorer in Java eclipse project?
- How to run Java package program
- What is the use of FileInputStream and FileOutputStream in classes in Java?
- How to skip certain classes in StackFrame in Java 9?

Advertisements