instanceof 判断一个对象是否为一个类的实例,是为true ,否为false
class Animal{} class Cat extends Animal{} /**instanceof 判断一个对象是否为一个类的实例*/ public class InstanceofTest { public static void main(String[] args) { System.out.println(null instanceof Animal);//false System.out.println(null instanceof Cat);//false System.out.println(new Cat() instanceof Animal);//true System.out.println(new Cat() instanceof Cat);//true System.out.println(new Animal() instanceof Animal);//true System.out.println(new Animal() instanceof Cat);//false } }