instanceof运算符的前一个操作数通常是一个引用变量,后一个操作数通常是一个类(也可以是接口,可以把接口理解成一种特殊的类);
用于判断前面的对象是否是后面的类,或者其子类,实例类的实例。如果是返回true,反之false;
public class InstanceofTest{
public static void main(String [] args){
Object hello="Hello";
hello instanceof Object;//返回true
hello instanceof String;返回true ,String是Object的子类
hello instanceof Comparable;//返回true ,String 实现类Comparable 接口
hello instanceof Math;//返回false,Math与Object没有继承关系
}
}