在动物类的以下代码中,当我删除ClimbTrees()方法时,为什么它会生成错误
public class Refr1
{
public static void main(String[] args)
{
Animal objChimp = new Chimp();
objChimp.ClimbTrees();
}
}
class Animal
{
void ClimbTrees()
{
System.out.println("I am Animal Which Climb Tree");
}
}
class Chimp extends Animal
{
void ClimbTrees()
{
System.out.println("I am Chimp Which Climb Tree");
}
}
如果我删除 Animal 类中的ClimbTrees(),它会显示以下错误
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method ClimbTrees() is undefined for the type Animal