I have a Meeting class and I want to create a BusinessMeeting class which extends Meeting.
This is my Meeting class:
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;
}
This is my BusinessMeeting class:
public class BusinessMeeting extends Meeting {
public BusinessMeeting() {
super();
}
}
In my BusinessMeeting class, I am getting the error:
constructor Meeting in class Meeting cannot be applied to given types; required: String,String,int,int found: no arguments
I am not really sure why I am getting that error message. Shouldn't the BusinessMeeting class inherit all of the variables from my Meeting class?
The extends keyword extends a class (indicates that a class is inherited from another class). In Java, it is possible to inherit attributes and methods from one class to another. We group the "inheritance concept" into two categories: subclass (child) - the class that inherits from another class.
You can't extend two or more classes at one time. Multiple inheritance is not allowed in java.
You extend a class when you want the new class to have all the same features of the original, and something more. The child class may then either add new functionalities, or override some funcionalities of the parent class.
You can extend any class as long as its not final.
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;
}
}
Now say you want to extend your BusinessMeeting
class with a 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;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With