day10-对象的向上向下转型代码实现

This commit is contained in:
2026-07-27 15:57:00 +08:00
parent 05adc05745
commit b9ea2c1322
5 changed files with 53 additions and 0 deletions
@@ -28,6 +28,10 @@ Person p = new Student();//这里才使用了多态
一定要注意:编译看左边,运行看右边。
多态中:代码的书写时,父类中没有的变量和方法是不能写的,因为编译看左边,编译器会直接报错
多态的核心好处:“以不变,应万变”---通过抽象定义统一接口,应对具体实现的变化。它让代码简洁,灵活,更
容易扩展。
*/
public class Demo09 {
public static void main(String[] args) {