class Person3 {
 public void fun1() {
  System.out.println("1.Person1()");
 }
 public void fun2() {
  System.out.println("2.Person2()");
 }
}
class Student extends Person3 {
 public void fun1() {
  System.out.println("3.Person3()");
 }
 public void fun4() {
  System.out.println("4.Person4()");
 }
}
public class Test14 {
 public static void main(String[]args) {
  Person3 p = new Student();//类的多态之“向上转型”:父类对象通过子类对象去实例化
  Student s = (Student)p; //“向下转型”:父类对象可以转化为子类对象
  s.fun1();                //向上转型自动完成,向下转型必须进行强制类型转换
 }
}

posted on 2013-03-25 19:37  翻滚的小豆哥  阅读(210)  评论(0编辑  收藏  举报