Cannot instantiate the type Keche
?答答租車 ?問題
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
}
2016-09-07
Qiche qiche[5];?
qiche[0]=new Keche(500,"奧迪A4",4)
qiche[1]=new Keche(400,"馬自達6",4)
......
這樣試試 我也就猜猜 ?
希望對你有幫助
如果沒對 ? 等你解決問題的時候 ?麻煩 告訴我一聲 ?我也好奇