Java 类/编译器错误的扩展

Java 类/编译器错误的扩展,java,oop,Java,Oop,请看以下课程: public class Person { public void whatAreYou(){ System.out.println("Person"); } } public class Student extends Person { public void whatAreYou(){ System.out.println("Student"); } } 当我试着打电话时 Person p = new Student(); p.whatAr

请看以下课程:

public class Person {
  public void whatAreYou(){
    System.out.println("Person");
  }
}

public class Student extends Person {
  public void whatAreYou(){
    System.out.println("Student");
  }
}
当我试着打电话时

Person p = new Student();
p.whatAreYou();
我的编译器告诉我:

error: cannot find symbol
我假设这意味着这里没有找到whatAreYou()方法,但我不明白这一点。必须允许写入
Person p=new Student()
,因为
Student
Person
的扩展。因此,当我们在运行程序时调用
p.whatAreYou()
时,java应该调用Student类中的方法whatAreYou()。但是编译器似乎已经不接受这里的引用,尽管两个方法在各自的类中甚至有相同的名称


谁能给我解释一下为什么会这样

当编译器说:
找不到符号时,表示该类或方法不可访问,或不存在

在这种情况下,与之相关的是
IO
类,您应该将其替换为System.out,这是java程序的默认输出

您的代码应该是:

public class Person {
    public void whatAreYou(){
        System.out.println("Person");
    }
}


这将非常好地工作

假设下面的代码在Student.java中,这就像预期的一样

班级人员{
公共无效whatAreYou(){
系统输出打印号(“人员”);
}
}
公营班级学生人数{
公共无效whatAreYou(){
System.out.println(“学生”);
}
公共静态void main(字符串[]args){
人员p=新学生();
p、 whatAreYou();
}
} 

向我们展示完整的代码。重新编译您的整个项目,可能会清理IDE的缓存。没有完整的代码,这是一个旧的考试题,这就是给我们的所有内容。@而且我还是犯了一个错误。
IO
是否正常工作?它不是标准的javaclass@Julian你说你试图编译代码,但它给了你一个错误。因此,必须有更多的代码,因为你发布的不是可以编译的完整代码。这并不能回答问题——它只是说这个问题目前没有意义,真的。这更适合于评论-我知道你现在不能评论,但这不适合添加答案。请阅读关于“你的代码工作”答案的元讨论:
public class Student extends Person {
    public void whatAreYou(){
        System.out.println("Student");
    }
}