编写一个Car类,具有String类型的属性品牌,具有功能drive;
定义其子类Aodi和Benchi,具有属性:价格、型号;具有功能:变速;
定义主类E,在其main方法中分别创建Aodi和Benchi的对象并测试对象的特
性。
package zuoye;
public class Cat {
String pinpai;
double sudu;
double jiage;
String xinghao;
public String getPinpai() {
return pinpai;
}
public void setPinpai(String pinpai) {
this.pinpai = pinpai;
}
public double getSudu() {
return sudu;
}
public void setSudu(double sudu) {
this.sudu = sudu;
}
public double getJiage() {
return jiage;
}
public void setJiage(double jiage) {
this.jiage = jiage;
}
public String getXinghao() {
return xinghao;
}
public void setXinghao(String xinghao) {
this.xinghao = xinghao;
}
public String drive()
{
return "汽车已发动,请注意!";
}
}
package zuoye;
public class Aodi extends Cat {
public double biansu()
{
double sudu=super.getSudu()+20;
return sudu;
}
}
package zuoye;
public class Benchi extends Cat{
public double biansu1()
{
double sudu=super.getSudu()+40;
return sudu;
}
}
package zuoye;
public class E {
public static void main(String[] args) {
Aodi ad=new Aodi();
ad.setPinpai("奥迪 ");
ad.setXinghao("奥迪x7 ");
ad.setJiage(5000000.0);
System.out.println("汽车品牌是:"+ad.getPinpai()+"型号是:"+ad.getXinghao()+"价格是:"+ad.getJiage());
System.out.println(ad.drive());
System.out.println("启动后速度是:"+ad.biansu()+"km/h");
Benchi bc=new Benchi();
bc.setPinpai("奔驰 ");
bc.setXinghao("奔驰555 ");
bc.setJiage(10000000.0);
System.out.println("汽车品牌是:"+bc.getPinpai()+"型号是:"+bc.getXinghao()+"价格是:"+bc.getJiage());
System.out.println(bc.drive());
System.out.println("启动后速度是:"+bc.biansu1()+"km/h");
}
}