I'm trying to make a constructor that takes 2 elements of type Punto
and assigns it to the instance variables, in my superclass I already have a constructor but I want one more in my subclass so first in my subclass I call the superclass constructor and then I try to add one more with the following error:
constructor in class cannot be applied to given types.
Superclass:
public class Poligono implements Figura {
Punto[] vertici;
public Poligono(Punto[] vertici) throws IndexOutOfBoundsException {
if(vertici == null || vertici.length<3) {
throw new IndexOutOfBoundsException();
}
this.vertici = vertici;
}
Subclass:
package figura;
import punto.Punto;
public class Rettangolo extends Poligono{
Punto p1;
Punto p2;
public Rettangolo(Punto[] vertici) throws IndexOutOfBoundsException {
super(vertici);
}
public Rettangolo(Punto p1, Punto p2) throws NullPointerException{
if(p1==null || p2==null) throw new NullPointerException();
this.p1 = p1;
this.p2 = p2;
}
in my second constructor i get the error:
constructor Poligono in class Poligono cannot be applied to given types;
required: Punto[]
found: no arguments
reason: actual and formal argument lists differ in length