对象转型中的注意要点
向上转型时父类引用不能指向子类中的独有属性
上代码
public class Armor extends Item{
public int armorExclusive = 99;
public static void main(String[] args) {
Item item = new Armor();
Armor armor = new Armor();
System.out.println(item.armorExclusive); //报错
System.out.println(armor.armorExclusive);
}
@Override
public void test() {
// TODO Auto-generated method stub
System.out.println("this is son");
}
}