我有一个 session 类,我想创建一个扩展 session 的BusinessMeeting类。
这是我的 session 类(class):
public class Meeting {
private String name;
private String location;
private int start, stop;
public Meeting(String name, String location, int start, int stop) {
this.name = name;
this.location = location;
this.start = start;
this.stop = stop;
}
这是我的BusinessMeeting类(class):
public class BusinessMeeting extends Meeting {
public BusinessMeeting() {
super();
}
}
在我的BusinessMeeting类中,出现错误:
构造函数Meeting类中的Meeting不能应用于给定的类型;
必需:String,String,int,int
找到:没有参数
我不太确定为什么会收到该错误消息。 BusinessMeeting类不应该从Meeting类继承所有变量吗?
最佳答案
public class Meeting {
public Meeting(String name, String location, int start, int stop) {
this.name = name;
this.location = location;
this.start = start;
this.stop = stop;
}
}
现在说您想用
BusinessMeeting
扩展businessId
类。public class BusinessMeeting {
private Integer businessId;
public BusinessMeeting(String name, String location, int start, int stop, int business) {
// because super calls one of the super class constructors(you can overload constructors), you need to pass the parameters required.
super(name, location, start, stop);
businessId = business;
}
}
关于Java-扩展类,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19501638/