测试instanceof:如果是女人的instanceof返回true, 则一定是人的instance
/*
* 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 {} ///:~