請指導(dǎo),多謝各位了!
public?class?Vehicle?{ int?people; double?price; String?sp; ???public?Vehicle(int?people,?double?price,?String?sp){ ???????this.people?=?people; ???????this.price?=?price; ???????this.sp?=?sp; ???} ???public?void?use(){ ???????System.out.println("**功能**??"?+?"載客:"?+?people?+"??價(jià)格:"?+?price); ???????System.out.println("到達(dá)目的地時(shí)間"?+?sp); ???} }
子類1:
public?class?Car?extends?Vehicle?{ ????public?Car(int?people,?double?price,?String?sp){ ????????super(people,?price,?sp); ????} }
子類2:
public?class?Boat?extends?Vehicle?{ ??public?Boat(int?people,?double?price,?String?sp){ ??????super(people,?price,?sp); ??} }
子類3:
public?class?Plane?extends?Vehicle?{ ????public?Plane(int?people,?double?price,?String?sp){ ????????super(people,?price,?sp); ????} }
main函數(shù):
public?class?Main?{ ????public?static?void?main(String?args[]){ ????????Vehicle?car?=?new?Car(4,23.4,"4小時(shí)"); ????????Car?car2?=?new?Car(5,20.2,"也是4小時(shí)"); ????????Boat?boat?=?new?Boat(100,40.0,"3小時(shí)"); ????????Plane?plane?=?new?Plane(200,345.5,"1小時(shí)"); ????????car.use(); ????????car2.use(); ????????boat.use(); ????????plane.use(); ????} }
運(yùn)行結(jié)果:
**功能**? 載客:4? 價(jià)格:23.4
到達(dá)目的地時(shí)間4小時(shí)
**功能**? 載客:5? 價(jià)格:20.2
到達(dá)目的地時(shí)間也是4小時(shí)
**功能**? 載客:100? 價(jià)格:40.0
到達(dá)目的地時(shí)間3小時(shí)
**功能**? 載客:200? 價(jià)格:345.5
到達(dá)目的地時(shí)間1小時(shí)
2019-05-29
這個(gè)是什么意思?
2019-05-27
相互學(xué)習(xí)相互學(xué)習(xí)。