instanceof

instanceof

  • 判断有无关系
   public static void main(string[] args) {
//object > String
//object > Person > Teacher
// object > Person > student
        object object = new Student();
        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
        System.out.print1n(object instanceof String); //False
        system.out.println("==============");

        Person person = new Student();
        system.out.println(person instanceof Student);// true
        System.out.println(person instanceof Person);// true
        System.out.println(person instanceof object);// true
        System.out.println(person instanceof Teacher); //False
        //System. out. println(person instanceof String); //编译报错!
}
上一篇:Day07


下一篇:Linux builtin 命令