java之instanceof操作符

a intanceof A:判断a是否是类A的的一个实例,返回值为boolean

public class Person extends Object{}

public class Student extends Person{}

public class Graduate extends Person{}

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

上一篇:typeof操作符和instanceof操作符的区别 标签: JavaScript 2016-08-01 14:21 113人阅读 评论(


下一篇:JavaScript instanceof 运算符深入剖析