public Square(Coordinates c, Color co, int w, int l) {
super(4, c, co);
this.w = w;
this.l = l;
}
Yes you would be correct. However you also need to assign the values of w
and l
.
Question
I have a class shape with a constructor that takes (int Sides, Coodinates c, Color co) in its constructor, in the class square I don't want to have "int Sides" in the constructor, how do I do this?
//Shape
public Shape(int sides, Coordinates c, Color co) {
this.sides = sides;
this.c = c;
this.co = co;
}
//Square
//Like this is gives me an error saying I need to include sides into my
//constructor. I don't want to request the number of sides when creating
//a square, it will always be 4, how do I do this?
public Square(Coordinates c, Color co, int w, int l) {
//blah blah
}
Would I be correct in assuming I would have to pass the value 4 using super(4, c, co) ?
Solution
public Square(Coordinates c, Color co, int w, int l) {
super(4, c, co);
this.w = w;
this.l = l;
}
Yes you would be correct. However you also need to assign the values of w
and l
.