# 02/Java
[윤성우 열혈자바] 15-3. instanceof 연산자
장딴지연
2019. 10. 22. 11:19
반응형
instanceof 연산자의 기본
class Cake {
}
class CheeseCake extends Cake {
}
class StrawberryCheeseCake extends CheeseCake {
}
public static void main(String[] args) {
Cake cake = new StrawberryCheeseCake();
if (cake instanceof Cake) { ... } // true
if (cake instanceof CheeseCake) { ... } // true
if (cake instanceof StrawberryCheeseCake) { ... } // true
}
if (ref instanceof ClassName)
ref가 ClassName 클래스의 인스턴스를 참조하면 true 반환
ref가 ClassName를 상속하는 클래스의 인스턴스이면 true 반환
참조변수 instanceof 클래스이름
반응형