
For example, there are now two packages:

Now I want to implement the call to Employee in the Boss class. How to do it? ?
(Video tutorial recommendation: java video)
Employee.java:
package payroll2;
public class Employee {
public void move(){
System.out.print("this is employee");
}
} If you want to call the package, you can use the import keyword , and then use the instantiation of the calling class to call the method inside.
Boss.java:
package payroll;
import payroll2.Employee;
public class Boss {
public static void main(String args[]) {
new Employee().move();
}
}Recommended tutorial: Getting started with java development
The above is the detailed content of How to call a class in another package in java. For more information, please follow other related articles on the PHP Chinese website!