package cn.cph.TestHomeWork;
public class Car {
String carType;
String carnum;
public Car() {
}
public Car(String carType,String carnum) {
this.carType = carType;
this.carnum = carnum;
}
void start() {
System.out.println("我是车,我已经启动!");
}
void end() {
System.out.println("我是车,我已经停止!");
}
}
********************************************************************
package cn.cph.TestHomeWork;
public class TaxiCar extends Car {
String company;
public TaxiCar() {
}
public TaxiCar(String carType,String carnum,String company) {
super(carType,carnum);
this.company = company;
}
void start() {
System.out.println("乘客您好,我是"+company+",我的车牌:"+carnum+",您要去哪里?");
}
void end() {
System.out.println("目的地已到,欢迎下次乘坐!");
}
}
*****************************************************************
package cn.cph.TestHomeWork;
public class OwnCar extends Car {
String ownerName;
public OwnCar() {
super();
}
public OwnCar(String carType, String carnum,String ownerName) {
super(carType, carnum);
this.ownerName=ownerName;
}
public void start() {
System.out.println("我是"+ownerName+",我的汽车我做主!");
}
public void end() {
System.out.println("目的地已到,我们去happy吧!");
}
}
*****************************************************************************************
package cn.cph.TestHomeWork;
public class Test {
public static void main(String[] args) {
Car car = new Car();
car.start();
car.end();
System.out.println("------------------------------------");
TaxiCar taxiCar = new TaxiCar("丰田花冠", "豫A12345", "鸿运公司");
taxiCar.start();
taxiCar.end();
System.out.println("------------------------------------");
OwnCar owncar = new OwnCar("奔驰S600", "豫A00001", "武大郎");
owncar.start();
owncar.end();
}
}