作业2
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了作业2相关的知识,希望对你有一定的参考价值。
编写一个Car类,具有String类型的属性品牌,具有功能drive;
定义其子类Aodi和Benchi,具有属性:价格、型号;具有功能:变速;
定义主类E,在其main方法中分别创建Aodi和Benchi的对象并测试对象的特
性。
package Car; public class Car { private String pinpai; private double sudu; public String getPinpa() { return pinpai; } public void setPinpa(String pinpa) { this.pinpai = pinpa; } public double getSudu() { return sudu; } public void setSudu(double sudu) { this.sudu = sudu; } public String drive(){ return "汽车已启动!"; } } package Car; 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 double biansu(){ double sudu=super.getSudu()+10; return sudu; } } package Car; 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 double biansu(){ double sudu=super.getSudu()+10; return sudu; } } package Car; public class E { public static void main(String[] args){ Aodi aodi=new Aodi(); aodi.setJiage(666666); aodi.setXinghao("奥迪A6"); aodi.setSudu(50); System.out.println("奥迪车的型号是:"+aodi.getXinghao()+" 价格是:"+aodi.getJiage()); System.out.println(aodi.drive()); System.out.println("启动后的速度为:"+aodi.biansu()); Benchi benchi=new Benchi(); benchi.setJiage(888888); benchi.setXinghao("奔驰S600"); benchi.setSudu(45); System.out.println("奔驰车的型号是:"+benchi.getXinghao()+" 价格是:"+benchi.getJiage()); System.out.println(benchi.drive()); System.out.println("启动后的速度为:"+benchi.biansu()); } }
以上是关于作业2的主要内容,如果未能解决你的问题,请参考以下文章
HTML5期末大作业:餐饮美食网站设计——咖啡(10页) HTML+CSS+JavaScript 学生DW网页设计作业成品 web课程设计网页规划与设计 咖啡网页设计 美食餐饮网页设计...(代码片段