测试instanceof:如果是女人的instanceof返回true, 则一定是人的instance

测试instanceof:


/*

* Created on Sep 23, 2004

*

* To change the template for this generated file go to

* Window>Preferences>Java>Code Generation>Code and Comments

*/

package think;

/**

* @author mengjun.jiang

*

* To change the template for this generated type comment go to

* Window>Preferences>Java>Code Generation>Code and Comments

*/

public class Test {

/**

* @param strings

*/

public void expect(String[] strings) {

// TODO Auto-generated method stub

}

public static void main(String [] args){

Pet o = new Gerbil();

if(o instanceof Gerbil){

System.out.println("o is instance of Gerbil");

}else{

System.out.println("o is not instance of Gerbil");

}

if(o instanceof Pet){

System.out.println("o is instance of Pet");

}else{

System.out.println("o is not instance of Gerbil");

}

}

}






//: think:Gerbil.java

package think;

public class Gerbil extends Rodent {} ///:~



//: c10:Pet.java

package think;

public class Pet {} ///:~





posted on 2004-09-23 16:33  笨笨  阅读(993)  评论(1编辑  收藏  举报

导航