每日代码系列(24)---终章
1 abstract class OutputAlphabet { 2 public abstract void output(); 3 } 4 class OutputEnglish extends OutputAlphabet { 5 public void output() { 6 for(char c='a';c<='z';c++) { 7 System.out.printf("%3c",c); 8 } 9 } 10 } 11 class ShowBoard { 12 void showMess(OutputAlphabet show) { //参数show是OutputAlphabet类型的对象 13 show.output(); 14 } 15 } 16 public class Example7_2 { 17 public static void main(String[] args) { 18 ShowBoard board=new ShowBoard(); 19 board.showMess(new OutputEnglish()); //向参数传递OutputAlphabet的子类OutputEnglish的对象 20 board.showMess(new OutputAlphabet() { //向参数传递OutputAlphabet的匿名子类的对象 21 public void output() { 22 for(char c='α';c<='ω';c++) { 23 System.out.printf("%3c",c); 24 } 25 } 26 } 27 ); 28 } 29 }
24天的陪伴,舍不得结束这个系列。不过,新的系列即将降临,尽请期待!!!