/*
汽车类
/
public abstract class MotoVehicle {
/
}
public MotoVehicle(String no,String brand,int perRend){
this.no=no;
this.brand=brand;
this.perRend=perRend;
}
}
/*
桥车类
*/
public class Car extends MotoVehicle{
private String type;//型号
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Car(){
}
public Car(String no,String brand,int perRent,String type){
super(no,brand,perRent);//调用父类的构造函数
this.type=type;
}
/*
/*
客车类
*/
public class Bus extends MotoVehicle{
private int seatCount;//座位数
public int getSeatCount() {
return seatCount;
}
public void setSeatCount(int seatCount) {
this.seatCount = seatCount;
}
public Bus(){
}
public Bus(String no,String brand,int perRent,int seatCount){
super(no,brand,perRent);//调用父类的构造函数
this.seatCount=seatCount;
}
/*
/*
问题忘了写 float money=moto.calRent(days);这句看不懂 moto是父类MotoVehicle的对象 为什么调用的是子类的calRent()方法
子类是具体实现的类,结算费用是,肯定会找子类对应的方法,这是多态啊
就是方法重写,参考 http://gengu.iteye.com/blog/1114422
注意,和方法重载不是一回事。也不要说成“多态”,这些都是不正确,不规范的说法。
这是继承,面向对象三大特征之一
这是继承,面向对象三大特征之一