Memory Drive

instanceof +1
반응형

[CODE type="java"]
class A { }
class B extends A { }
class C extends B { }

public class instanceofTest
{
public static void main(String args[])
{
 B ob = new B();
 if (ob instanceof B) System.out.println("B의 객체");
 if (ob instanceof C) System.out.println("C의 객체");
 if (ob instanceof A) System.out.println("A의 객체");
 
 A oa = new A();
 if (oa instanceof A) System.out.println("A의 객체");
 if (oa instanceof B) System.out.println("B의 객체");
 if (oa instanceof C) System.out.println("C의 객체");
 
}

}

[/HTML][/CODE]

반응형

'Computer_IT > JAVA' 카테고리의 다른 글

2차원 배열 생성, 값 배정  (1) 2006.04.05
swing 자바 Addtion  (0) 2006.04.04
예약어 super  (0) 2006.04.01
멤버 변수의 상속  (0) 2006.04.01
오버로딩(Overloading), 오버라이딩(Overriding)  (0) 2006.04.01