标签:
编写一个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();
标签:
原文地址:http://www.cnblogs.com/jskbk/p/5520303.html