作者:weirou520 //小汽車最多能載5噸貨物 interface car{ int MAX_LOADWare= 5; } //出租車最多能載4個人 interface taxs{ int MAX_LOADMan =4; } //一般的汽車最高時速能達到150千米/小時 class fathercar{ int intspeed =150; int drivespeed() { return intspeed; } } ///假如想要公共汽車有 小汽車的功能,也要有一般汽車,出租車的功能, 可以如下設置: //首先公共汽車(bus)繼續一般汽車,然后實現car 和taxs 接口(因為一個類只答應有一個子類) class bus extends fathercar implements car,taxs{ PRivate int intware; //定義2個私有變量(可以認為是bus自身有的特性) private int intman; public int loadware() { intware=MAX_LOADWare; return intware; } public int loadman() { intman =MAX_LOADMan; return intman; } } public class eat{ public static void main(String[] args){ bus nbbus= new bus(); //打印公共汽車的功能 System.out.println("the max drive speed of bus"+ nbbus.drivespeed());//最高速度 System.out.println("the max ware weight of bus"+ nbbus.loadware());//最高載重量 System.out.println("the max man number of bus"+ nbbus.loadman());//可以載4個人 }