class Employee
|
class Manager
向上校正,总是允许的,Manager 直接使用父类Employee 的方法。
向下校正,必须用instanceof 检验,才能将一个Employee 转换为Manager 对象。
public void test(Employee e){
if (e instanceof Manager){
Manager m = (Mnager)e;
...
}
}
|
class Manager
向上校正,总是允许的,Manager 直接使用父类Employee 的方法。
向下校正,必须用instanceof 检验,才能将一个Employee 转换为Manager 对象。
public void test(Employee e){
if (e instanceof Manager){
Manager m = (Mnager)e;
...
}
}