1 package oo.day04; 2 //向上造型演示 3 public class UpDemo { 4 public static void main(String[] args) { 5 /* 6 Eoo o1 = new Eoo(); 7 o1.e = 1; 8 o1.show(); 9 */ 10 11 /* 12 Foo o2 = new Foo(); 13 o2.f = 1; 14 o2.say(); 15 o2.e = 2; 16 o2.show(); 17 */ 18 19 Eoo o3 = new Foo(); //向上造型 20 o3.e = 1; 21 o3.show(); 22 //o3.f = 2; //编译错误,点出来什么,看引用的类型 23 } 24 } 25 26 class Eoo{ 27 int e; 28 void show(){ 29 } 30 } 31 class Foo extends Eoo{ 32 int f; 33 void say(){ 34 } 35 }