instanceof与类型转换(引用类型)
好好理解!!!
public class Application {
public static void main(String[] args) {
//instanceof
//Object > String
//Object > Person > Teacher
//Object > Person > Student
Object object = new Student();
//System.out.println(X instanceof Y);//能不能编译通过,就取决于X和Y之间是否存在父子关系;
//结果是true或者false ,X所指向的实例类型是Y的子类型,或者 X和 Y是有关系的
System.out.println(object instanceof Student);//true
System.out.println(object instanceof Person);//true
System.out.println(object instanceof Object);//true
System.out.println(object instanceof Teacher);//false,Teacher是另一条线,跟Student无关,跟这个类型一点关系都没有
System.out.println(object instanceof String);//false,String是 Object lang包下面的,更没关系了
System.out.println("==========