[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차원 배열 생성, 값 배정  (0) 2006/04/05
swing 자바 Addtion  (0) 2006/04/04
연산자 instanceof  (0) 2006/04/01
예약어 super  (0) 2006/04/01
멤버 변수의 상속  (0) 2006/04/01
오버로딩(Overloading), 오버라이딩(Overriding)  (0) 2006/04/01
Posted by 싸구려코드

Trackback Address :: http://sarangsai.com/trackback/39 관련글 쓰기

댓글을 달아 주세요