import oop.demo05继承.Teacher;
import oop.demo06多态.Person;
import oop.demo06多态.Student;
public class Appliaction {
public static void main(String[] args) {
//Object>String
//Object>Person>Teacher
//Object >Person >Studnt
Object object = new Student();
//System.out.println(x instanceof y);两者之间有无关系
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);//编译报错
}
}
/*
输出结果:
true
true
true
false
false
========================
true
true
true
*/
public class Appliaction{
public static void main(String[] args){
Person obj = new Student();
//高 低
//student将这个对象转换为Studen类型,我们就可以使用Student类型的方法了!
Student student=(Student)obj;
student.go();
//((Student)obj).go();
}
}
原文:https://www.cnblogs.com/FettersLove/p/13741549.html