日期:2014-05-20 浏览次数:21057 次
public class Square extends Rectangle {
private int length;
public Square(int x, int y, // 左边顶点坐标
int length // 边长
) {
super(x, y, x + length, y + length);
this.length = length;
}
public int getLength() {
return length;
}
//.奶.奶.的.,.说.老.子.回.复.正.文.中.有.非.法.词.或.词.组.!
//.后.续.两.个.方.法.不.覆.盖.也.可.以.,.只.是.举.个.例.子,如.果.是.其.他.例.子,.
//.原.来.代.码.开.销.很.大.的.话.,.建.议.覆.盖。
//.在.你.这.个.例.子.中.,.也.建.议.在.Rectangle中.设.置.width/height.属.性.,.在.构.造.的.时.候.一.并.计.算.,.这.样.加.快.速.度
@Override
public int getWidth() {
return length;
}
@Override
public int getHeight() {
return length;
}
}