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

How to call a class in another package in java

王林
Release: 2020-05-16 10:22:09
Original
8037 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:
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
Latest Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template