其他分享
首页 > 其他分享> > 十一、instanceof和类型转换

十一、instanceof和类型转换

作者:互联网

public class Demo02 {


    public static void main(String[] args) {
        //Object>Person>Student
        //Object>Person>Teacher
        //Object>String
        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);
        System.out.println(object instanceof String);

        System.out.println("=======================");
        Person person = new Student();
        System.out.println(person instanceof Student);
        System.out.println(person instanceof Person);
        System.out.println(person instanceof Object);
        System.out.println(person instanceof Teacher);
        //System.out.println(person instanceof String);//编译报错

        System.out.println("=======================");

        Student student = new Student();
        System.out.println(student instanceof Student);
        System.out.println(student instanceof Person);
        System.out.println(student instanceof Object);

        //System.out.println(student instanceof Teacher);//编译报错
        //System.out.println(person instanceof String);//编译报错
    }
}

 

标签:instanceof,类型转换,十一,Object,System,Student,println,out
来源: https://www.cnblogs.com/epiphany8/p/16265224.html