我有一个Meeting类,我想创建一个扩展Meeting的BusinessMeeting类.
这是我的Meeting类:
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;
}
Run Code Online (Sandbox Code Playgroud)
这是我的BusinessMeeting类:
public class BusinessMeeting extends Meeting {
public BusinessMeeting() {
super();
}
}
Run Code Online (Sandbox Code Playgroud)
在我的BusinessMeeting类中,我收到错误:
构造函数类会议中的会议不能应用于给定类型; required:String,String,int,int found:无参数
我不确定为什么我收到该错误消息.BusinessMeeting类不应该继承Meeting类中的所有变量吗?
您创建的构造函数接受4个参数,您可以不使用任何参数.如果你想在没有参数的情况下初始化它 - 添加一个空构造函数Meeting:
public Meeting(){}
Run Code Online (Sandbox Code Playgroud)
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;
}
}
Run Code Online (Sandbox Code Playgroud)
现在说你想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;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24032 次 |
| 最近记录: |