프로그래밍
[JAVA] instanceof
ReturnToHome
2016. 12. 24. 21:51
반응형
Object 형이 어떤 형인지 판별할때 사용.
객체가 특정 클래스나 인터페이스로부터 생성된 객체인지를 판별 해주는 연산자.
형식) 객체참조변수 instanceof Type
ex)
public class TestA {}
public class TestB extends TestA{}
public class TestC extneds TestB{}
각각 testA, testB, testC 로 객체 생성하였다 했을 시
testA instanceof testA > true
testA instanceof testB > false
testA instanceof testC > false
testB instanceof testA > true
testB instanceof testB > true
testB instanceof testC > false
testC instanceof testA > true
testC instanceof testB > true
testC instanceof testC > true
반응형