比如我有抽象類Shape
,是可以獲得形狀的座標:訪問超域
public abstract class Shape{
private int x;
private int y;
public Shape(int x, int y){
this.x=x;
this.y=y
}
public abstract void onDraw();
}
現在我有類Rect
的擴展從Shape
:
public class Rect extends Shape{
private int height;
private int width;
public Rect(int height, int width){
this.height=height;
this.width=width;
}
@Override
public void onDraw(){
//this method should get the width and height and the coordinates x and y, and will print the shape rect
}
}
現在我的問題是:我如何從Rect
內獲得抽象類Shape
的座標x和y?
請遵循命名約定 –