JAVA面向对象的学习 -------多态 Instance of 的学习(类型转换)

public static void main(String[] args) {
//类型之间的转换 父 到 子 高 到 低
Person person = new Student();
//student这个对象装换为Student类型,我们就可以使用Student类型的方法了
Student student = (Student) person;//<===>((Student) person).go();
student.go();


//子 到 父 子类转换为父类,可能会丢失一些自己的方法
Student S1 = new Student();
Person P1 = student;
//P1.go(); 父类转换为子类可能会丢失方法
}


}


/*
1.父类的引用指向子类的对象.
2.把子类转换为父类,向上转型;
3.把父类转换为子类,向下转型;强制转换, 会丢失方法
4.方便方法的调用,减少重复的代码。简洁


抽象: 封装, 继承 ,多态 。 抽象类 , 接口。
*/



posted @ 2020-07-08 22:30  光光1234  阅读(115)  评论(0编辑  收藏  举报