instanceof1 instanceof instanceof다형성에서는 참조형 변수는 이름 그대로 다양한 자식을 대상으로 참조 가능하기에 어떤 인스턴스를 참조하는 지 확인이 필요한 경우 존재인스턴스의 타입을 확인하는 키워드"객체 instanceof 클래스" 형식으로 사용사용 예시new Parent() instanceof ParentParent p = new Parent() //같은 타입 truenew Child() instanceof ParentParent p = new Child() //부모는 자식을 담을 수 있다. truenew Parent() instanceof ChildChild c = new Parent() //자식은 부모를 담을 수 없다. falsenew Child() instanceof ChildChild c = new Child(.. 2024. 12. 31. 이전 1 다음