a intanceof A:判断a是否是类A的的一个实例,返回值为boolean
public class Person extends Object{}
public class Student extends Person{}
public class Graduate extends Person{}
代码语言:javascript复制public class Main {
public static void main(String[] args) {
Person p = new Person();
Student s = new Student();
Graduate g = new Graduate();
System.out.println(p instanceof Person);
System.out.println(s instanceof Person);
System.out.println(g instanceof Person);
}
}
输出:
true
true
true