Test instanceof:
/*
* Created on Sep 23,200 4
*
* To change the template for this generated file go
* Window & gt; preferences & gt; Java & gt; Code Generation & gt; Code and comments
*/
Package
Think;
/**
*@ AuthorMengjun. Jiang
*
* To change the template for this generated type comment go
* Window & gt; preferences & gt; Java & gt; Code Generation & gt; Code and comments
*/
Public
ClassTest {
/**
*@ ParamStrings
*/
Public VoidReverse CT (string [] strings ){
//TodoAuto-generated method stub
}
Public Static VoidMain (string [] ARGs ){
Pet o =
NewGerbil ();
If(OInstanceofGerbil ){
System. Out. println (
"O is instance of gerbil ");
}
Else{
System. Out. println (
"O is not instance of gerbil ");
}
If(OInstanceofPet ){
System. Out. println (
"O is instance of pet ");
}
Else{
System. Out. println (
"O is not instance of gerbil ");
}
}
}
//: Think: gerbil. Java
Package
Think;
Public
ClassGerbilExtendsRodent {}///:~
//: C10: Pet. Java
Package
Think;
Public
ClassPet {}///:~