想实现一个汽车经销商的系统,但是当我尝试实例在派生类中我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