错误:类型可转换必须实现继承的抽象方法car.rent(java.lang.string,int)
我的程序正在给出实现继承的抽象方法的错误消息。
在其中我应该在主要或类“ CAR”中实现该方法?
每次尝试运行程序时,我都会收到此错误消息
在子程序中显示错误,但我认为它源于主程序或类“ CAR”。
<Error: The type Convertible must implement the inherited abstract method
Car.Rent(java.lang.String, int)>
这是我的子程序,其中错误是:
public class Convertible extends Car {
//=========== CONSTRUCTOR ===========//
/* To instantiate a Convertible object
* @param code - The car code of this car
* @param make - The maker of this car
* @param model - The model name of this car
* @param openTopTime - The time it takes to open the convertible top (in seconds) */
private double openTopTime;
public Convertible( int code, String make, String model, double openTopTime ) {
super (id, make, model);
this.openTopTime = openTopTime;
}
/* Get the time it takes for the car to open it's convertible top
* @param renter - The renter's name */
public double OpenTopTime() {
return this.OpenTopTime;
}
}
和我的主要程序:
public class CRSMain {
public static void main(String[] args) {
CRS crs = new CRS();
String carListFilename = "CarList.txt";
Displayer c = new Displayer ();
c.Sedan ( cl );
c.Coupe ( c2 );
}
}
public class Displayer {
// Write a method that will dynamically display
public void Show( Car c ) {
// Calling overriden method.
Car c1 = new Sedan("1008","Honda","Civic","Good on gas");
}
}
import java.util.Date;
public abstract class Car {
// Global Variables for the car types
public static final int SEDAN = 0;
public static final int COUPE = 1;
public static final int CROSSOVER = 2;
public static final int CONVERTIBLE = 3;
private int id;
private String make;
private String model;
private int mileage;
private boolean isRent;
private String renter;
private int allowableDist;
private Date dueDate;
//============== Constructor ===============
/* Default constructor for initiating a Car object */
public Car() {
this.dueDate = new Date();
}
/* To instantiate a Car object
* @param id - The car Id of this car
* @param make - The maker of this car
* @param model - The model name of this car */
public Car( int id, String make, String model) {
this.id = id;
this.make = make;
this.model = model;
}
//============= Private Methods ===============
/* May add your own private methods here */
//============= Public Methods ================
/* Get the Car ID
* @return - The car code */
public int GetId() {
return this.id; // Dummy return value. Needs to be modified.
}
/* Get the car maker
* @return - The car maker */
public String GetMake() {
return this.make; // Dummy return value. Needs to be modified.
}
/* Get the car model
* @return - The car model */
public String GetModel() {
return this.model; // Dummy return value. Needs to be modified.
}
My program is giving an error message of implementing an inherited abstract method.
Where should I implement the method, in my main or the class "Car" ?
I keep getting this error message every time I try to run my program,
The error shows in the Subprogram, but I think it stems from the main program or the class "Car".
<Error: The type Convertible must implement the inherited abstract method
Car.Rent(java.lang.String, int)>
This is my Subprogram, where the error is:
public class Convertible extends Car {
//=========== CONSTRUCTOR ===========//
/* To instantiate a Convertible object
* @param code - The car code of this car
* @param make - The maker of this car
* @param model - The model name of this car
* @param openTopTime - The time it takes to open the convertible top (in seconds) */
private double openTopTime;
public Convertible( int code, String make, String model, double openTopTime ) {
super (id, make, model);
this.openTopTime = openTopTime;
}
/* Get the time it takes for the car to open it's convertible top
* @param renter - The renter's name */
public double OpenTopTime() {
return this.OpenTopTime;
}
}
And my main program:
public class CRSMain {
public static void main(String[] args) {
CRS crs = new CRS();
String carListFilename = "CarList.txt";
Displayer c = new Displayer ();
c.Sedan ( cl );
c.Coupe ( c2 );
}
}
public class Displayer {
// Write a method that will dynamically display
public void Show( Car c ) {
// Calling overriden method.
Car c1 = new Sedan("1008","Honda","Civic","Good on gas");
}
}
import java.util.Date;
public abstract class Car {
// Global Variables for the car types
public static final int SEDAN = 0;
public static final int COUPE = 1;
public static final int CROSSOVER = 2;
public static final int CONVERTIBLE = 3;
private int id;
private String make;
private String model;
private int mileage;
private boolean isRent;
private String renter;
private int allowableDist;
private Date dueDate;
//============== Constructor ===============
/* Default constructor for initiating a Car object */
public Car() {
this.dueDate = new Date();
}
/* To instantiate a Car object
* @param id - The car Id of this car
* @param make - The maker of this car
* @param model - The model name of this car */
public Car( int id, String make, String model) {
this.id = id;
this.make = make;
this.model = model;
}
//============= Private Methods ===============
/* May add your own private methods here */
//============= Public Methods ================
/* Get the Car ID
* @return - The car code */
public int GetId() {
return this.id; // Dummy return value. Needs to be modified.
}
/* Get the car maker
* @return - The car maker */
public String GetMake() {
return this.make; // Dummy return value. Needs to be modified.
}
/* Get the car model
* @return - The car model */
public String GetModel() {
return this.model; // Dummy return value. Needs to be modified.
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论