我正在尝试实现一个比父类具有更多参数的类的构造函数,唯一的共同点是标题。当我尝试在 Book 类中实现构造函数时,它显示错误“隐式 super 构造函数 Item() 未定义”。
public class Book extends Item {
private String author = "";
private String ISBN = "";
private String publisher = "";
public Book(String theTitle, String theAuthor, String theIsbn, String thePublisher){
}
}
父类构造函数;
public abstract class Item {
private String title;
private int playingTime;
protected boolean gotIt;
private String comment;
public Item(String title, int playingTime, boolean gotIt, String comment) {
super();
this.title = title;
this.playingTime = playingTime;
this.gotIt = gotIt;
this.comment = comment;
}
提前致谢。
最佳答案
您的父类(super class)没有无参数默认构造函数,因此您必须使用 super() 关键字传递默认值显式调用父类(super class)的重载构造函数。
public Book(String theTitle, String theAuthor, String theIsbn, String thePublisher){
super(thTitle,0,false,null)
}
关于java - 无法实现构造函数(隐式 super 构造函数 Item() 未定义),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15309992/