다형성
이란 한 객체가 여러가지 타입을 가질 수 있는 성질이다.
부모 클래스 타입의 참조 변수로 자식 클래스의 인스턴스를 참조할 수 있다.
class Person {
}
class Student extends Person {
}
public class Test {
public static void main(String[] args) {
Person p1 = new Student(); // 가능
// Student s1 = new Person(); // 불가능, error
System.out.println(p1 instanceof Person); // true
System.out.println(p1 instanceof Student); // true
}
}