废话不说,直接看例子
public class TestXY { public static void main(String[] args) { String string = new String(); Object object = new Object(); //用法:实例对象 instanceof 类名 System.out.println(string instanceof String);//运行结果为true System.out.println(string instanceof Object);//运行结果为true System.out.println(object instanceof String);//运行结果为false } }
运行结果为boolean类型。