码迷,mamicode.com
首页 > 其他好文 > 详细

CAR

时间:2016-09-21 10:20:22      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:

24.编写一个Car类,具有String类型的属性品牌,具有功能drive;

定义其子类Aodi和Benchi,具有属性:价格、型号;具有功能:变速;

定义主类E,在其main方法中分别创建Aodi和Benchi的对象并测试对象的特

性。

package zuoye;

public class Car 
{
    public String pinpai;
    
    public String getPinpai() {
        return pinpai;
    }

    public void setPinpai(String pinpai) {
        this.pinpai = pinpai;
    }

    public void drive()
    {
        System.out.println("具有功能变速");
    }
    public String getInfo()
    {
        return pinpai;
    }
    
}
package zuoye;

public class Benchi extends Car
{
    public double jiage;
    public String xinghao;
    
    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 void biansu()
    {
        System.out.println("bian      su");
    }
    public String getInfo()
    {
        return xinghao+jiage+getPinpai();
    }
}
package zuoye;

public class E {

    public static void main(String[] args)
    {
        Aodi a =new Aodi();
        Benchi b =new Benchi();
        a.setPinpai("奥迪");
        a.setXinghao("R8");
        a.setJiage(2000000);
        b.setPinpai("奔驰");
        b.setXinghao("很贵");
        b.setJiage(12345567);
        System.out.println(a.getInfo());
        System.out.println(b.getInfo());

    }

}

 

CAR

标签:

原文地址:http://www.cnblogs.com/Levi1995/p/5891459.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!