java 继承练习题7
Posted 风起,唯有努力生存
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 继承练习题7相关的知识,希望对你有一定的参考价值。
编写一个Car类,具有final类型的属性品牌,具有功能drive;
定义其子类Aodi和Benchi,具有属性:价格、型号;具有功能:变速;
定义主类E,在其main方法中分别创建Aodi和Benchi的对象并测试对象的特
性。
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的主要内容,如果未能解决你的问题,请参考以下文章