Question

I'm writing a group of subclasses associated with abstract super class. There is one default constructor but when I am making another constructor it's giving me the following error:

Implicit super constructor Event() is undefined. Must explicitly invoke another constructor

My code is below:

public class Meeting extends Event {

private String location;
private String subject;
private String notes;
private String attendeeName;

// Array of attendees as string
private String[] listofAttendees = new String[10];

public Meeting(Date dueDate, Date reminderDate, String location,
        String subject, String notes) {
    super(dueDate, reminderDate);
    this.location = location;
    this.subject = subject;
    this.notes = notes;

}

public Meeting(String attendeeName) {   // this is the error constructor 
    this.attendeeName = attendeeName;
}

public String getLocation() {
    return location;
}

public void setLocation(String location) {
    this.location = location;
}

public String getSubject() {
    return subject;
}

public void setSubject(String subject) {
    this.subject = subject;
}

public String getNotes() {
    return notes;
}

public void setNotes(String notes) {
    this.notes = notes;
}

public String[] addAttendee(String name) {
    // adding for loop for adding the list of attendees to the array
    for (int i = 0; i < listofAttendees.length; i++) {
        // array index(i) = name of attendee
        listofAttendees[i] = name;
    }

    return listofAttendees;
}

}
Was it helpful?

Solution

The object that you're extending,Event, does not have a constructor that takes no arguments. So you need to call super and specify arguments like you do in your other constructor.

OTHER TIPS

In your constructor:

public Meeting(String attendeeName) {
    this.attendeeName = attendeeName;
}

You are not explicitly calling super like you are in your other constructor. So, Java is implicitly trying to call the default constructor on the base class, which is Event(). You need to either define a default constructor in Event, or you need to add an explicit call in this constructor to one of the defined Event constructors.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top