向上转型(Son-->Father),程序会自动完成
父类 父类对象 = 子类实例
向下转型(Father-->Son),强制类型转换
子类 子类对象 = (子类)父类实例
class Father { public void tell() { System.out.println("Father tell"); } } class Son extends Father { public void tell() { System.out.println("Son tell"); } }
public class Demo { public static void main(String args[]) { //向上转型 Father father = new Son(); father.tell(); //向下转型(向下转型时要先进行向上转型) Father father = new Son(); Son son = (Son) father; son.tell(); } }