大家好,我在重复构造函数方面遇到了错误,但根据我的作业,我需要另一个构造函数但不同的字段。
规范:
- session – 地点、主题、字符串数组形式的与会者列表、注释、addAttendee(String name) 方法。
- 用于将单个与会者设置为与会者数组的构造函数。
- 构造函数接受分配给与会者列表的字符串数组。
- 另外两个构造函数与前两个构造函数相同,但允许将注释字段设置为字符串。
这是部分代码
public Meeting(String name) {
this.name = name;
listofAttendees[count] = name;
count++;
// blank constructor for no parameter super constructor
}
// Constructor to accept an array of strings assign to the list of Attendees
public Meeting(String[] listofAttendees) {
this.listofAttendees = listofAttendees;
}
// CONStructors for note field
public Meeting(String notes) { // Error here!
this.notes = notes;
}
最佳答案
不能有多个具有相同名称和相同类型参数的方法。
仅创建一个带有名称和注释的构造函数,如果您只想分配即名称,请传递一个空参数作为注释。
public Meeting(String names, String notes);
关于java - session 类型中的重复方法 session (字符串) - 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23714062/