Java Reference
In-Depth Information
The payEmployee() method of the Boss class has a parameter of type
Employee. The parameter is actually of type payroll.Employee, but because
Boss is in the payroll package, the payroll prefix of Employee is not needed.
What happens if Boss 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.
Suppose that the Boss class is in a package named management. The follow-
ing Boss class uses the fully qualified name when referring to the Employee
class in the payroll package.
package management;
public class Boss
{
public void payEmployee(payroll.Employee e)
{
e.mailCheck();
}
}
Because Boss uses the full name payroll.Employee, the payroll package does
not need to be imported. If the Boss class imports the payroll package, how-
ever, it can refer to Employee without using the payroll prefix, as demon-
strated by the following Boss class.
package management;
import payroll.*;
public class Boss
{
public void payEmployee(Employee e)
{
e.mailCheck();
}
Search WWH ::




Custom Search