Home > Java > javaTutorial > body text

How to call a class in another package in java

王林
Release: 2020-05-16 10:22:09
Original
7839 people have browsed it

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

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

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!

Related labels:
source:php.cn
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!