
- 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 access Java package from another package
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 wild card (*). For example −
import payroll.*;
- The class itself can be imported using the import keyword. For example −
import payroll.Employee;
A class file can contain any number of import statements. The import statements must appear after the package statement and before the class declaration.
- Related Articles
- Moving objects from one package to another package in SAP HANA
- How to import classes from within another directory/package in Java?
- How to use functions from another package in Golang?
- Create and Access a Python Package
- How to run Java package program
- How to use sub-package in Java?
- How to load classes at runtime from a folder or Java package
- How to import Pandas package?
- How to import everything from a python namespace / package?
- How to find package explorer in Java eclipse project?
- How to use classes in other package in Java
- How to BIND a DBRM into a PACKAGE and PACKAGE into a PLAN?
- How do I write package names in Java?
- overriding method different package in java
- How to put two public classes in a Java package.

Advertisements