1. 程式人生 > 實用技巧 >每日程式碼系列(22)

每日程式碼系列(22)

 1 abstract class MotorVehicles {
 2   abstract void brake();
 3 }
 4 interface MoneyFare {
 5   void charge();
 6 }
 7 interface ControlTemperature {
 8   void controlAirTemperature();
 9 }
10 class Bus extends MotorVehicles implements MoneyFare {
11   void brake() {
12     System.out.println("公共汽車使用轂式剎車技術");
13 } 14 public void charge() { 15 System.out.println("公共汽車:一元/張,不計算公里數"); 16 } 17 } 18 class Taxi extends MotorVehicles implements MoneyFare,ControlTemperature { 19 void brake() { 20 System.out.println("計程車使用盤式剎車技術"); 21 } 22 public void charge() { 23 System.out.println("計程車:2元/公里,起步價3公里");
24 } 25 public void controlAirTemperature() { 26 System.out.println("計程車上安裝了Hair空調"); 27 } 28 } 29 class Cinema implements MoneyFare,ControlTemperature { 30 public void charge() { 31 System.out.println("電影院:門票,十元/張"); 32 } 33 public void controlAirTemperature() { 34 System.out.println("電影院安裝了中央空調");
35 } 36 } 37 public class Example6_3 { 38 public static void main(String[] args) { 39 Bus bus101=new Bus(); 40 Taxi buleTaxi=new Taxi(); 41 Cinema redStarCinema=new Cinema(); 42 MoneyFare fare; 43 ControlTemperature temperature; 44 fare=bus101; 45 bus101.brake(); 46 fare.charge(); 47 fare=buleTaxi; 48 temperature=buleTaxi; 49 buleTaxi.brake(); 50 fare.charge(); 51 temperature.controlAirTemperature(); 52 fare=redStarCinema; 53 temperature=redStarCinema; 54 fare.charge(); 55 temperature.controlAirTemperature(); 56 } 57 }

最近忙著考試,沒有時間學習新的東西,這個系列也差不多快要結束了,我要構思一下然後開一個新的系列。在此,感謝各位一直以來對我的支援!