Home > Java > javaTutorial > body text

Access Java classes in other packages

PHPz
Release: 2023-09-12 22:09:08
forward
634 people have browsed it

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();
   }
}
Copy after login

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
Copy after login
  • You can use the import keyword and the wildcard character (*) to import a package. For example -
import payroll.*;
Copy after login
  • The class itself can be imported using the import keyword. For example -
import payroll.Employee;
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template