たとえば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
、extendsfromのクラスができました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
}
}
今私の質問は:抽象クラスの座標xとyをShape
内部から取得するにはどうすればよいRect
ですか?
それらがある限り、それらを取得することはできませんprivate
。protected
代わりにそれらを作成します。
詳細については、こちらをご覧ください。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加