向上转型把一个子类类型安全的的变为父类类型的赋值,称为向上转型。eg:Student s= new Student(); Person p=s;向下转型把一个父类类型强制转型为子类类型,就是向下转型Person p1 = new Student(); // upcasting, okPerson p2 = new Person();Student s1 = (Student) p1; // okStudent s2 = (Student) p2; // runtime error! C
java
2024-01-12
61 点赞
0 评论
92 浏览