code is as follows:
the first paragraph of code:
package cn.kgc.pack1;
import java.util.Scanner;
public class Person { //""
private int age;
private String name;
private String gender;
public Person() {
this.name = "";
}
public Person(String name) {
this.name = name;
}
public String setName(String name) {
return this.name;
}
public String setGender(String gender) {
return this.gender;
}
public int setAge(int age) {
return this.age;
}
public void say() {
System.out.println("\r\n :" + this.name + "\r\n:" + this.gender +
"\r\n:" + this.age + "" );
}
}
second paragraph of code:
package cn.kgc.pack2;
import cn.kgc.pack1.Person;
public class PersonTest {
public static void main(String[] args) {
Person hanbing = new Person();
hanbing.setName("");
hanbing.setGender("");
hanbing.setAge(22);
//hanbing.work();
hanbing.say();
//hanbing.work("");
}
}
The code is not the point. I compiled both pieces of code successfully and put them in two different packages. The path to the package is as follows:
mainPersonTest:
Why on earth is this?
my code is copied from the textbook, and the compilation is also passed. In theory, if you put it in the same folder, it should be able to run, but it will fail if you put it in a different package.