美文网首页
instanceof是什么意思

instanceof是什么意思

作者: NecromancerLin | 来源:发表于2018-04-11 15:28 被阅读5次

这个关键字的用法是:A instanceof B ,返回值为boolean类型,用来判断A是否是B的实例对象或者B子类的实例对象。如果是则返回true,否则返回false。

如:Person p = new Person() ; //

Man  m = new Man() ; //Man是Person的子类

Animal a = new Animal() ;

m instanceof Man //返回true

m instanceof Animal//返回false

m instanceof Person//返回true

相关文章

网友评论

      本文标题:instanceof是什么意思

      本文链接:https://www.haomeiwen.com/subject/vhqzhftx.html