嘿傢伙,所以我正在與形狀簡單的Java繼承程序。我知道我的問題不是什麼新東西,但我已經研究過,而且通常的問題是super參數不匹配父類的構造函數參數類型。但是,我有匹配的參數,仍然得到這個錯誤。該錯誤發生在平行四邊形的超級語句中。任何幫助將不勝感激,謝謝!Java的繼承與構造函數
public abstract class Quadrilateral implements Shapes
{
double base, height, perimeter, area, s1, s2, s3, s4;
String name;
public Quadrilateral(String name, double base, double height, double side1, double side2, double side3, double side4){
this.name = name;
this.base = base;
this.height = height;
s1 = side1;
s2 = side2;
s3 = side3;
s4 = side4;
}
public double getHeight(){
return height;
}
public double getS1(){
return s1;
}
public double getS2(){
return s2;
}
public double getS3(){
return s3;
}
public double getS4(){
return s4;
}
public double getPerimeter(){
return s1 + s2 + s3 + s4;
}
public String toString(){
String str;
str = "name is " + name + "\n";
str += "area is " + area + "\n";
str += "perimeter is " + perimeter + "\n";
str += "sides 1-4 are " + s1 + ", " + s2 + ", " + s3 + "and " + s4;
return str;
}
}
類新
public class Parallelogram extends Quadrilateral
{
public Parallelogram(String name, double base, double height){
super(name, side1, side2, side1, side1, side2, side2); //RECIEVE ERROR HERE WITH THE FIRST SIDE1!!!
}
public double getArea(){
area = base * height;
return area;
}
public String getName(){
return name;
}
}
類新
public class Rectangle extends Parallelogram
{
public Rectangle(String name, double side1, double side2){
super(name, side1, side2);
}
}
類新
public class Square extends Rectangle
{
public Square(String name, double side1){
super(name, side1, side2);
}
}