• 汽车.


      

    编写一个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");
    }

    }

  • 相关阅读:
    P2207 Photo
    P1022 计算器的改良
    P1003 铺地毯
    P3014 [USACO11FEB]牛线Cow Line && 康托展开
    P4180 【模板】严格次小生成树[BJWC2010]
    P2776 [SDOI2007]小组队列
    P2426 删数
    P1948 [USACO08JAN]电话线Telephone Lines
    P1978 集合
    P1564 膜拜
  • 原文地址:https://www.cnblogs.com/smile-dream/p/5892281.html
Copyright © 2020-2023  润新知