答答租车 问题
package ZuChe; //虚拟 汽车类 public abstract class Qiche { int rent;//价格 String name;//汽车名字 public abstract void shuChu();//虚拟方法体 shuChu public Qiche(int rent ,String name){ this.rent =rent ;//有参构造方法 初始化成员变量 this.name=name; } //定义 的getRent 方法 public int getRent(){ return rent; } }
package ZuChe;
public abstract class Keche extends Qiche {
int num;
public void shuChu(){
System.out.println(name+" "+rent+"/天"+"载人:"+num);
}
public Keche(int rent ,String name, int num){
super(rent,name);
this.num=num;
}
}
package ZuChe;
public abstract class Khche extends Qiche {
int ton;
int num;
public Khche(int rent, String name,int num,int ton) {
super(rent,name);
this.ton=ton;
this.num=num;
// TODO Auto-generated constructor stub
}
public void shuChu() {
// TODO Auto-generated method stub
System.out.println(name+" "+rent+"/天"+" "+"载人:"+num+"载货"+ton);
}
}
package ZuChe;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("欢迎使用答答租车系统:");
System.out.println("您是否要租车:1是 0否");
Scanner input = new Scanner(System.in);
int t = input.nextInt();
Qiche[] qiche={
new Keche(500,"奥迪A4",4),
new Keche(400,"马自达6",4),
new Khche(450,"皮卡雪6",4,2),
new Keche(800,"金龙",20),
new Huoche(400,"松花江",4),
new Huoche(1000,"依维柯",20)
} ;
}
}
在Qiche[] qiche = {
new Keche 红线 Cannot instantiate the type Keche
new Khche 红线Cannot instantiate the type Keche
}
Qiche qiche[5];
qiche[0]=new Keche(500,"奥迪A4",4)
qiche[1]=new Keche(400,"马自达6",4)
......
这样试试 我也就猜猜
希望对你有帮助
如果没对 等你解决问题的时候 麻烦 告诉我一声 我也好奇