하나의 객체가 여러 가지 타입을 가질 수 있는 것을 의미
부모 클래스 타입의 참조 변수로 자식 클래스 타입의 인스턴스를 참조할 수 있습니다.
class Parent {...}
class Child extends Parent{...}
Parent p1 = new Child(); // 허용
Child c1 = new Parent(); // 오류
(변환할타입의클래스이름) 변환할참조변수
class Parent { ... }
class Child extends Parent { ... }
Parent p1 = new Child(); //생략 가능
Child c1 = (Child)(new Parent()); //생략 불가능
참조변수 instanceof 클래스이름
Parent p = new Child();
System.out.println(p instanceof Object); // true
System.out.println(p instanceof Parent); // true
System.out.println(p instanceof Child); // true