我知道其他人有一個非常類似的問題,我和我曾試圖應用這些答案,我的代碼,但它仍然無法正常工作,所以我希望你的球員之一將能夠看看我的代碼,並解釋在哪裏出了問題......直角平面,找不到符號錯誤
這是我的代碼有:二
public class Square extends Rectangle{
String Colour;
public Square (int x, int y, int h, int w, String Co){
super (x,y,h,w);
Colour=Co;
System.out.println("Constructing a Square now");
}
public void showColour(){
System.out.println("The colour of the square is " + Colour);
}
}
部分:
public class InheritProgram {
public static void main (String [] args){
Square One= new Square (10,20, 15, 15, "blue");
Square colour =new Square();
colour.showColour();
//GeometricShape center= new displayCenter();
}
}
這是錯誤Im g ETTING:
C:\Users\Karen\Documents\Java\Lab8-1\InheritProgram.java:5: error: constructor Square in class Square cannot be applied to given types;
Square colour =new Square();
^
required: int,int,int,int,String
found: no arguments
reason: actual and formal argument lists differ in length
1 error
Tool completed with exit code 1
任何幫助將是非常讚賞
爲什麼你方構造帶的高度和寬度,高度平方=總是它的寬度。問題就出現了,因爲你必須提供價值,當你創建一個新的正方形,因爲你在這裏做的:第一廣場=新廣場(10,20,15,15日,「藍」);,您還必須在這裏做的:方形顏色=新廣場(); – w4etwetewtwet