【发布时间】:2016-10-15 09:04:48
【问题描述】:
/** * 张中正于 2016 年 10 月 15 日创建。 */
公共类扩展测试 {
static Dog d = new Dog();
public static void main(String[] args) {
Animal a = d;
System.out.println(a instanceof Animal);//true
System.out.println(a instanceof Dog);//true
System.out.println(d instanceof Animal);//true
System.out.println(d instanceof Dog);//true
}
static class Animal {
}
static class Dog extends Animal {
}
}
为什么都是真的??????
【问题讨论】:
-
这里有三个应该很明显,如果你花一点时间调查
instanceof或者只是慢慢考虑这个名字,另一个也是。
标签: java