作者:weirou520 //小汽車最多能載5噸貨物 interface car{ int MAX_LOADWare= 5; } //出租車最多能載4個(gè)人 interface taxs{ int MAX_LOADMan =4; } //一般的汽車最高時(shí)速能達(dá)到150千米/小時(shí) class fathercar{ int intspeed =150; int drivespeed() { return intspeed; } } ///假如想要公共汽車有 小汽車的功能,也要有一般汽車,出租車的功能, 可以如下設(shè)置: //首先公共汽車(bus)繼續(xù)一般汽車,然后實(shí)現(xiàn)car 和taxs 接口(因?yàn)橐粋€(gè)類只答應(yīng)有一個(gè)子類) class bus extends fathercar implements car,taxs{ PRivate int intware; //定義2個(gè)私有變量(可以認(rèn)為是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個(gè)人 }