24.编写一个Car类,具有String类型的属性品牌,具有功能drive; 定义其子类Aodi和Benchi,具有属性:价格型号;具有功能:变速; 定义主类E,在其main方法中分别创建Aodi和(
Posted 张好好
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了24.编写一个Car类,具有String类型的属性品牌,具有功能drive; 定义其子类Aodi和Benchi,具有属性:价格型号;具有功能:变速; 定义主类E,在其main方法中分别创建Aodi和(相关的知识,希望对你有一定的参考价值。
package zhongqiuzuoye; public class Car { String brand; public void drive() {} }
package zhongqiuzuoye; public class Aodi extends Car{ public double price; public String model; public double speed; public Aodi(double price,String model,double speed) { this.price=price; this.model=model; this.speed=speed; System.out.println("价格为:"+price+"\t型号为:"+model+"\t初始速度为:"+speed); } double setSpeed(double s) { speed+=s; System.out.println("当前车速为:"+speed); return speed; } }
package zhongqiuzuoye; public class Benchi extends Car{ public double price; public String model; public double speed; public Benchi(double price,String model,double speed) { this.price=price; this.model=model; this.speed=speed; System.out.println("价格为:"+price+"\t型号为:"+model+"\t初始速度为:"+speed); } double setSpeed(double s) { speed+=s; System.out.println("当前车速为:"+speed); return speed; } }
package zhongqiuzuoye; public class E { public static void main(String[] args) { Aodi a4=new Aodi(300000,"A4",40); a4.setSpeed(-10); Benchi e200=new Benchi(500000,"e200",50); e200.setSpeed(50); } }
以上是关于24.编写一个Car类,具有String类型的属性品牌,具有功能drive; 定义其子类Aodi和Benchi,具有属性:价格型号;具有功能:变速; 定义主类E,在其main方法中分别创建Aodi和(的主要内容,如果未能解决你的问题,请参考以下文章