码迷,mamicode.com
首页 > 编程语言 > 详细

java 继承练习题7

时间:2016-05-23 16:44:13      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

编写一个Car类,具有final类型的属性品牌,具有功能drive

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

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

性。

public class Car {
    private final String  Pinpai="";
    
    public String getPinpai() {
        return Pinpai;
    }

    public void drive()
    {
        System.out.println("开车中");
    }
    
    
public class Aodi extends Car {

    private double jiage;
    private 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("速度改变");
    }
}
public class Benchi extends Car {
    private double jiage;
    private 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("速度改变");
    }
public class E {

    public static void main(String[] args) {
        Aodi a=new Aodi();
        a.setJiage(388888);
        System.out.println(a.getJiage());
        a.setXinghao("x5");
        System.out.println(a.getXinghao());
        a.biansu();
        Benchi b=new Benchi();
        b.setJiage(266666);
        System.out.println(a.getJiage());
        b.setXinghao("B200");
        System.out.println(a.getXinghao());
        
        b.biansu();

技术分享

java 继承练习题7

标签:

原文地址:http://www.cnblogs.com/jskbk/p/5520303.html

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