System.out.println(x instanceof y);
能不能编译通过
查看x和y有没有继承关系
继承关系
//object>String
//object>>Person>Teacher
//object>Person>Student
Object ob=new Student();
System.out.println(ob instanceof Student);//true
System.out.println(ob instanceof Person);//true
System.out.println(ob instanceof Object);//true
System.out.println(ob instanceof Teacher);//false
System.out.println(ob instanceof String);//false
Person person =new Student();
System.out.println(person instanceof Student);//true
System.out.println(person instanceof Person);//true
System.out.println(person instanceof Object);//true
System.out.println(person instanceof Teacher);//false
// System.out.println(person instanceof String);//编译报错
Student s =new Student();
System.out.println(s instanceof Student);//true
System.out.println(s instanceof Person);//true
System.out.println(s instanceof Object);//true
// System.out.println(s instanceof Teacher);//编译报错
// System.out.println(s instanceof String);//编译报错