我正在尝试为矩形和椭圆形创建一个抽象形状类,我给形状赋予的唯一抽象方法是draw方法,但是在给它一个构造函数之后,矩形类中的所有内容给我一个错误,即颜色和其他变量具有私有访问权限,这是我的代码:
public abstract class Shape{
private int x, y, width, height;
private Color color;
public Shape(int x, int y, int width, int height, Color color){
setXY(x, y);
setSize(width, height);
setColor(color);
}
public boolean setXY(int x, int y){
this.x=x;
this.y=y;
return true;
}
public boolean setSize(int width, int height){
this.width=width;
this.height=height;
return true;
}
public boolean setColor(Color color){
if(color==null)
return false;
this.color=color;
return true;
}
public abstract void draw(Graphics g);
}
class Rectangle extends Shape{
public Rectangle(int x, int y, int …Run Code Online (Sandbox Code Playgroud)