标签:
1 package oo.day04; 2 //重写的演示 3 public class OverrideDemo { 4 public static void main(String[] args) { 5 /* 6 Goo o1 = new Goo(); 7 o1.show(); //父类show 8 9 Hoo o2 = new Hoo(); 10 o2.show(); //子类show 11 */ 12 13 Goo o3 = new Hoo(); //向上造型 14 o3.show(); //子类show 15 } 16 } 17 18 class Goo{ 19 void show(){ 20 System.out.println("父类show"); 21 } 22 } 23 class Hoo extends Goo{ 24 void show(){ //重写(覆盖) 25 super.show(); //调用父类的show方法 26 System.out.println("子类show"); 27 } 28 }
标签:
原文地址:http://www.cnblogs.com/xiaziteng/p/4725730.html