我有一个 Meeting 类,我想创建一个扩展 Meeting 的 BusinessMeeting 类。
这是我的 session 类:
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 类:
public class BusinessMeeting extends Meeting {
public BusinessMeeting() {
super();
}
}
在我的 BusinessMeeting 类中,我收到错误:
类 session 中的构造函数 session 不能应用于给定类型; 必需:字符串、字符串、整数、整数 发现:没有参数
我不太确定为什么会收到该错误消息。 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;
}
}
现在假设您想使用 businessId
扩展您的 BusinessMeeting
类。
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/