Computer[] labComputers = new Computer[10];
和
public class Computer {
...
void toString(){
// print computer specs
}
}
public class Notebook extends Computer{
...
void toString(){
// print computer specs + laptop color
}
}
每个下标变量labComputers[i]都可以引用一个Computer对象或一个Notebook对象,因为Notebook它是Computer. 对于方法调用labComputers[i].toString(),多态性确保调用正确的toString方法。
我想知道如果我们这样做
Notebook[] labComputers = new Notebook[10];
Computer如果我引用对象和Notebook对象,我会得到什么类型或错误