Задача из подпункта по приведению типов объектов:
//What is wrong in the following code?
public class Test {
public static void main(String[] args) {
Object fruit = new Fruit();
Object apple = (Apple)fruit;
}
}
class Apple extends Fruit {
}
class Fruit {
}
Что тут не так?
fruit
имеет runtime-типFruit
, но не являетсяApple
.