Home  >  Article  >  Java  >  How to call a class in another package in java

How to call a class in another package in java

王林
王林Original
2020-05-16 10:22:097893browse

How to call a class in another package in java

For example, there are now two packages:

How to call a class in another package in java

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!

Statement:
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