업캐스팅된 클래스를 다시 원래의 타입으로 형 변환
하위 클래스로의 형 변환은 명시적으로 해야 함
Customer vc = new VIPCustomer(); //묵시적
VIPCustomer vCustomer = (VIPCustomer)vc; //명시적
AnimalTest.java
public void testDownCasting(ArrayList<Animal> list) {
for(int i =0; i<list.size(); i++) {
Animal animal = list.get(i);
if ( animal instanceof Human) {
Human human = (Human)animal;
human.readBooks();
}
else if( animal instanceof Tiger) {
Tiger tiger = (Tiger)animal;
tiger.hunting();
}
else if( animal instanceof Eagle) {
Eagle eagle = (Eagle)animal;
eagle.flying();
}
else {
System.out.println("error");
}
}
}