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("=======");
}
}
标签:instanceof,object,System,println,true,out 来源: https://www.cnblogs.com/shuqiqi/p/16482652.html