instanceof (类型转换)引用类型,判断对象什么类型。

// Object > String
// Object > Person > Student
// Object > Person > Teacher
Object object = new Student();
        System.out.println(object instanceof Student);
        System.out.println(object instanceof Person);
        System.out.println(object instanceof Object);
        System.out.println(object instanceof Teacher);

查看是否有父子关系。

方便方法的调用,减少重复的代码。

子类转换成父类,向上转型。(可能丢失自己本来的一些方法)

父类转换成子类,向下转型,强制转换。