想實現一個汽車經銷商的系統,但是當我嘗試實例在派生類中我Car
類,我得到錯誤信息未定義構造錯誤
Multiple markers at this line
- The constructor Car(String, int, String, String, double, double) is
undefined
這裏的父類車:
package Number3;
public class Car {
private String plateNum;
private int year;
private String make;
private String model;
protected double costPrice;
protected double sellingPrice;
public Car()
{
plateNum = "";
year = 1990;
make = "";
model = "";
costPrice = 0.0;
sellingPrice = 0.0;
}
public Car(String plateNum,int year,String make,String model,double costPrice,double sellingPrice)
{
this.plateNum = plateNum;
this.year = year;
this.make = make;
this.model = model;
this.costPrice = costPrice;
this.sellingPrice = sellingPrice;
}
public double getCostPrice()
{
return costPrice;
}
public double computeSellPrice()
{
sellingPrice = costPrice;
return sellingPrice;
}
public void displayCarDetails()
{
System.out.println("Plate number: "+plateNum);
System.out.println("Year: "+year);
System.out.println("Make: "+make);
System.out.println("Cost price: "+costPrice);
System.out.println("Selling price: "+sellingPrice);
}
}
和子類newCar
:
package Number3;
public class newCar extends Car{
private double tax;
public newCar(String plateNum,int year, String make, double costPrice, double sellingPrice, double tax)
{
super(plateNum,year,make,costPrice,sellingPrice); //where the error is found
this.tax = (25/100);
}
public double computeSellPrice()
{
sellingPrice = costPrice + (costPrice * tax);
return sellingPrice;
}
public void displayCarDetails()
{
super.displayCarDetails();
}
}
任何幫助,將不勝感激。
構造確實不那裏 - 你的Super()調用中有一個小錯誤。 – chsh 2015-02-09 18:21:39
您的超類構造函數也需要模型參數。你沒有通過它的新車,但你這樣做的二手車。 – 2015-02-09 18:21:46
@RaviThapliyal你能回答這個問題嗎?舉例說明,因爲我不清楚。我還沒有完全掌握OOP的概念。 – 2015-02-09 18:24:07