《Java2实用教程(第三版)》第67页有下面一节代码,明明是书上例子,结果报错:
class 类人猿
{
private int n = 100;
void crySpeak(String s)
{
System.out.println(s);
}
}class People extends 类人猿
{
void computer(int a, int b)
{
int c = a * b;
System.out.println(c);
}
void crySpeak(String s)
{
System.out.println("**" + s + "**");
}
}class Example4_n
{
public static void main(String args[])
{
类人猿 monkey = new People(); //monkey是People对象的上转型对象
monkey.crySpeak("I love this game");
People people = People(monkey); //把上转型对象强制转换成子类的对象
people.computer(10, 10);
}
}People people = People(monkey)报警:没有为类型 Example4_n 定义方法 People(类人猿)