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'不一样。 –