这段代码编译得很好:
人.java
package people;
class Person{
private String name;
private int age;
public Person(String name, int age){
this.name = name;
this.age = age;
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
public int getAge(){
return age;
}
public void setAge(int age){
this.age = age;
}
}
这不会:
控制器.java
package people;
public class controller{
public static void main (String[] args){
Person mark = new Person();
mark.setName("Mark");
mark.setAge(24);
}
}
我收到此编译错误:
C:\Program Files\Java\jdk1.8.0_66\classes\controller.java:7: error: cannot find symbol
Person mark = new Person();
^
symbol: class Person
location: class controller
C:\Program Files\Java\jdk1.8.0_66\classes\controller.java:7: error: cannot find symbol
Person mark = new Person();
^
symbol: class Person
location: class controller
我对此进行了相当多的研究,但似乎无法弄清楚。我是否试图在我的 controller.java 文件中错误地实例化对象?谢谢。