-5

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;
}

}
Zong
  • 6,160
  • 5
  • 32
  • 46
user3617072
  • 3
  • 1
  • 4
  • Out of curiosity, did you try googling the error message first before asking here? – Mike B May 08 '14 at 15:22
  • yes but not getting enough answer, and that's why stack overflow website exists – user3617072 May 08 '14 at 15:23
  • 1
    Look at the link that I marked this a duplicate of. What from that answer is lacking? – Mike B May 08 '14 at 15:24
  • Or this one: http://stackoverflow.com/questions/9143317/java-inheritance-error-implicit-super-constructor-is-undefined – Mike B May 08 '14 at 15:25
  • Or this one: http://stackoverflow.com/questions/18954944/implicit-super-constructor-is-undefined-with-java-generics – Mike B May 08 '14 at 15:26
  • Or this one: http://stackoverflow.com/questions/5488134/java-implicit-super-constructor-employee-is-undefined-must-explicitly-invoke – Mike B May 08 '14 at 15:26
  • 1
    Those are just the first few SO results from searching for the error message. There are tons of other non-SO resources that also exactly explain how to fix this. Hopefully what you learn here is not how to fix this specific problem, but how to find the answer to a problem all by yourself without having to come here and ask a question that has been answered many, many times before. – Mike B May 08 '14 at 15:28

2 Answers2

0

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.

Evan Knowles
  • 7,426
  • 2
  • 37
  • 71
0

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.

Danny
  • 354
  • 1
  • 5
  • ok thanks allot you got my point :) one more thing, how can i add explicit call in this constructor ?\ – user3617072 May 08 '14 at 15:33
  • Look at the other Meeting constructor in your original post. The first line is: `super(dueDate, reminderDate);` That is an explicit call to the super constructor `Event(Date dueDate, Date reminderDate);` Is there an Event constuctor that takes a single String parameter for attendeeName? If so, add `super(attendeename);` as the first line of the constructor that is giving you problems. If not, you need to create a new constructor like that in Event, or you need call some other existing Event constructor via super. The call to super has to be the first thing in your constructor. – Danny May 09 '14 at 13:17