public class RectangleEx extends Rectangle
{
int height =0;
int width=0;
public RectangleEx(int height, int width)
{
super(height,width);
}
public RectangleEx()
{
super(0,0);
this.setHeight(5);
System.out.println(this.height);
}
}
誰能告訴我爲什麼,當使用第二個構造函數創建新的RectangleEx時,其高度爲0而不是5?這是超類中setHeight的代碼:子類設置方法不起作用
public void setHeight(int height)
{
this.height = height;
}
來自超類的'height'與您繼承的類的'height'不一樣。 –