instanceof

package src.com.qiQi.oop;

import src.com.qiQi.oop.Demo08.Person;
import src.com.qiQi.oop.Demo08.Student;
import src.com.qiQi.oop.Demo08.Teacher;

//测试类
public class Application {
public static void main(String[] args) {
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.println(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);//编译报错
System.out.println("=======");



}
}
posted @ 2022-07-15 19:54  书先生  阅读(60)  评论(0)    收藏  举报