[Java, 자바] instanceof란 ?
프로그래밍/Java2024. 4. 13. 10:00[Java, 자바] instanceof란 ?

instanceof란 ?instanceof는 객체 타입을 확인하는 연산자입니다 ! 형변환 가능 여부를 확인하여 true/false로 결과를 반환해줍니다. 주로 상속 관계에서 부모 객체인지 자식 객체인지 확인하는 데 사용됩니다 ! instanceof 사용방법instanceof의 기본 사용방법은 아래의 예시와 같이 "객체 instanceof 클래스"를 선언함으로써 사용할 수 있습니다.class Parent{}class Child extends Parent{}public class InstanceofTest { public static void main(String[] args){ Parent parent = new Parent(); Child child = new Child()..

image