subclass constructor problem
in
Programming Questions
•
10 months ago
Hey guys!
This is a bit confusing. I have a superclass which looks basically like this:
class Capsule {
PVector location;
PVector velocity;
PVector acceleration;
float r;
float wandertheta;
float maxforce;
float maxspeed;
color fillColor;
int name;
Capsule(float x, float y, color c, int nam) { //the class constructor
acceleration = new PVector(0,0);
velocity = new PVector(0,0);
location = new PVector(x,y);
r = 6;
wandertheta = 0;
maxspeed = 0.5;
maxforce = 0.05;
fillColor = c;
name = nam;
}
and some subclasses that look like this:
class MW1 extends Capsule {
MW1(float x_mw1, float y_mw1, color c_mw1, int nam_mw1) {
super(x_mw1,y_mw1,c_mw1,nam_mw1);
}
when I try to run the code I get the message that:
the constructor "file_name".MW1() is undefined
and a yellow line here:
ArrayList<Capsule> agents = new ArrayList<Capsule>();
for (int i = 0; i < 40; i++) {
if (i < 20) agents.add(new MW1());
...
Does anyone know what am I doing wrong? where exactly is the problem with the subclass constructor?
1