
- 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
Accessing a Java class in other 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 wildcard (*). For example −
import payroll.*;
- The class itself can be imported using the import keyword. For example −
import payroll.Employee;
- Related Articles
- Display the package name of a class in Java
- How to use classes in other package in Java
- What is the package for String Class in Java?
- What would getPackage() return for a class in unnamed package in Java?
- Accessing protected members in a C++ derived class
- Can I define more than one public class in a Java package?
- Accessing variables of two interfaces, which are same from an implementing class in java?
- How to resolve "Could not find or load main class package" in Java?
- What is a predefined package in Java?
- How to access Java package from another package
- overriding method different package in java
- Accessing Kotlin extension functions from Java
- Check for the availability of a package in Java
- How to use sub-package in Java?
- Difference between import and package in Java?

Advertisements