kapok

垃圾桶,嘿嘿,我藏的这么深你们还能找到啊,真牛!

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  455 随笔 :: 0 文章 :: 76 评论 :: 0 Trackbacks

public class TestClass {

 public static void main(String[] args) {
  
  Parent parent = new Parent();
  Child child = new Child();
  
  if (child instanceof Child){
   System.out.println("child instanceof Child is true!");
  } else {
   System.out.println("child instanceof Child is false!");
  }
  if (child instanceof Parent){
   System.out.println("child instanceof Parent is true!");
  } else {
   System.out.println("child instanceof Parent is false!");
  }
  if (child instanceof Person){
   System.out.println("child instanceof Person is true!");
  } else {
   System.out.println("child instanceof Person is false!");
  }
  
  if (Child.class.isInstance(child)){
   System.out.println("Child.class.isInstance(child) is true!");
  } else {
   System.out.println("Child.class.isInstance(child) is false!");
  }
  if (Parent.class.isInstance(child)){
   System.out.println("Parent.class.isInstance(child) is true!");
  } else {
   System.out.println("Parent.class.isInstance(child) is false!");
  }
  if (Person.class.isInstance(child)){
   System.out.println("Person.class.isInstance(child) is true!");
  } else {
   System.out.println("Person.class.isInstance(child) is false!");
  }
  
  if (Child.class.isAssignableFrom(Child.class)){
   System.out.println("Child.class.isAssignableFrom(Child.class) is true!");
  } else {
   System.out.println("Child.class.isAssignableFrom(Child.class) is false!");
  }
  if (Child.class.isAssignableFrom(Parent.class)){
   System.out.println("Child.class.isAssignableFrom(Parent.class) is true!");
  } else {
   System.out.println("Child.class.isAssignableFrom(Parent.class) is false!");
  }
  if (Child.class.isAssignableFrom(Person.class)){
   System.out.println("Child.class.isAssignableFrom(Person.class) is true!");
  } else {
   System.out.println("Child.class.isAssignableFrom(Person.class) is false!");
  }
  //Parent class implemented the Interface 'Person'
  if (Parent.class.isAssignableFrom(Person.class)){
   System.out.println("Parent.class.isAssignableFrom(Person.class) is true!");
  } else {
   System.out.println("Parent.class.isAssignableFrom(Person.class) is false!");
  }
  
  
  if (Child.class.isAssignableFrom(Child.class)){
   System.out.println("Child.class.isAssignableFrom(Child.class) is true!");
  } else {
   System.out.println("Child.class.isAssignableFrom(Child.class) is false!");
  }
  if (Parent.class.isAssignableFrom(Child.class)){
   System.out.println("Parent.class.isAssignableFrom(Child.class) is true!");
  } else {
   System.out.println("Parent.class.isAssignableFrom(Child.class) is false!");
  }
  if (Person.class.isAssignableFrom(Child.class)){
   System.out.println("Person.class.isAssignableFrom(Child.class) is true!");
  } else {
   System.out.println("Person.class.isAssignableFrom(Child.class) is false!");
  }
  //Parent class implemented the Interface 'Person'
  if (Person.class.isAssignableFrom(Parent.class)){
   System.out.println("Person.class.isAssignableFrom(Parent.class) is true!");
  } else {
   System.out.println("Person.class.isAssignableFrom(Parent.class) is false!");
  }
  
  
  
  
 }
}





public class Child extends Parent {

 public static void main(String[] args) {
 }
}



public class Parent implements Person {

 public static void main(String[] args) {
 }
}



public interface Person {

}


posted on 2005-05-09 10:12 笨笨 阅读(628) 评论(0)  编辑  收藏 所属分类: J2EEALLJ2SE

只有注册用户登录后才能发表评论。


网站导航: