java instanceof ?????????

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java instanceof ?????????相关的知识,希望对你有一定的参考价值。

?????????span   ??????   ??????   ??????   ??????   ??????   ??????   ?????????   pre   

???????????????java ??????instanceof ??????????????????????????????????????????????????????????????????????????????instanceof??????????????????????????????????????????????????????????????????????????????????????????????????????????????????

????????? 
result = object instanceof class 
????????? 
Result?????????????????? 
Object??????????????????????????????????????? 
Class????????????????????????????????????????????? 
????????? 
?????? object ??? class ????????????????????? instanceof ??????????????? true????????? object ??????????????????????????????????????? object ??? null???????????? false???

??????instanceof???Java????????????????????????????????????????????????

?????????????????????class?????????object????????????????????????????????????????????????????????????Java????????????????????????

?????????????????????class?????????object?????????????????????????????????????????????????????????????????????result????????????true??????????????????false?????????class????????????????????????????????????????????????false???

???????????????????????????

 interface Person {
    public void eat();
}

//?????????People

 class People implements Person {
    private int a=0;
    @Override
    public void eat() {
        System.out.println("======"+a);

    }

}

//??????xiaoming???

 class xiaoming extends People {
    private String name;

    @Override
    public void eat() {
        System.out.println("+++++++++");
    }
}

//?????????
class  Test {
    public static void main(String[] args) {
        People p = new People();
        xiaoming x = new xiaoming();
        System.out.println(p instanceof Person);
        System.out.println(p instanceof xiaoming);
        System.out.println(x instanceof Person);
        System.out.println(x instanceof People);

} }

 

???????????????

true
false
true
true

 

以上是关于java instanceof ?????????的主要内容,如果未能解决你的问题,请参考以下文章

Java 基础 - instanceof关键字

Java中的instanceof判断?

java中 instanceof 运算符的用法

java中instanceof用法

instanceof运算符的实质:Java继承链与JavaScript原型链

instanceof运算符的实质:Java继承链与JavaScript原型链