1 package day03; 2 3 public class UpTest { 4 public static void main(){ 5 Aoo o = new Aoo(); 6 o.a = 3; 7 o.b = 3; //错误,不能访问子类成员 8 9 Boo x = new Boo();10 x.b = 3;11 x.a = 3;12 x.say();13 14 Aoo y = new Boo(); //向上造型,父类引用指向子类对象15 y.a = 3;16 y.b = 3;17 18 }19 }20 21 class Aoo{22 int a;23 void show(){24 }25 }26 27 class Boo extends Aoo{28 int b;29 void say(){}30 }
父类、子类 :继承、向上造型。