public class Application {
public static void main(String[] args) {
Object object = new Student();
System.out.println(object instanceof Object);//true
System.out.println(object instanceof Person);//true
System.out.println(object instanceof Student);//true
System.out.println(object instanceof Teacher);//flase
//System.out.println(object instanceof String);
Person person = new Student();
System.out.println(person instanceof Object);//true
System.out.println(person instanceof Person);//true
System.out.println(person instanceof Student);//true
System.out.println(person instanceof Teacher);//flase
//System.out.println(person instanceof String);
Student student = new Student();
System.out.println(student instanceof Object);//true
System.out.println(student instanceof Person);//true
System.out.println(student instanceof Student);//true
//System.out.println(student instanceof Teacher);
//System.out.println(student instanceof String);
}
}
instanceof的使用
于 2022-09-03 23:37:08 首次发布