public
class
Test
{
public static void main( String [] args)
{
Object obj = new String();
System . out . println( obj instanceof String);
System . out . println( obj instanceof Integer);
System . out . println( obj instanceof Book);
}
class Book
{
}
}
public static void main( String [] args)
{
Object obj = new String();
System . out . println( obj instanceof String);
System . out . println( obj instanceof Integer);
System . out . println( obj instanceof Book);
}
class Book
{
}
}
结果为:true,false,false
但是如果这样写则不会通过编译:
System.out.println(new Integer() instanceof String);