public class Test {
public static void main(String[] args) {
//instanceof 父类子类
Father father1 = new Father();
System.out.println(father1 instanceof Father ); //ture
System.out.println(father1 instanceof Son ); //false
Father father2 = new Son();
System.out.println(father2 instanceof Father ); //ture
System.out.println(father2 instanceof Son ); //ture
Son son = new Son();
System.out.println(son instanceof Father ); //ture
System.out.println(son instanceof Son ); //ture
}
}
本文探讨了Java中实例化过程及其与父类子类之间的关系,通过代码实例展示了使用instanceof关键字判断对象类型的原理。
1万+

被折叠的 条评论
为什么被折叠?



