Home  >  Article  >  Java  >  Access Java classes in other packages

Access Java classes in other packages

PHPz
PHPzforward
2023-09-12 22:09:08602browse

Access Java classes in other packages

#You can understand it with the example of defining Boss class in salary package.

package payroll;
public class Boss {
   public void payEmployee(Employee e) {
      e.mailCheck();
   }
}

What if the Employee class is not in the payroll package? The Boss class must then use one of the following techniques to reference classes in different packages.

  • You can use the fully qualified name of the class. For example -
 payroll.Employee
  • You can use the import keyword and the wildcard character (*) to import a package. For example -
import payroll.*;
  • The class itself can be imported using the import keyword. For example -
import payroll.Employee;

The above is the detailed content of Access Java classes in other packages. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete