类不是抽象的,不会覆盖抽象方法

时间:2015-03-21 19:25:40

标签: java interface abstract

public interface Selectable {
     boolean getSelected();
     void setSelected();
     Shape contains(int x, int y); 
}

public class Square extends Rectangle implements Selectable {

    int side;
    boolean selected;

    public Square(int side){
        super(side);
        this.side = side;
    }

    public String toString(){
        return " is square with side: " + side + ". It's area is: " + getArea() + "\n";
    }

    public void setSelected(boolean selected){
        this.selected = selected;
    }

    public boolean getSelected(){
        return selected;
    }

    public Shape contains(int x, int y){

    }
}

没有编译

error: Square is not abstract and does not override abstract method setSelected() in Selectable 

如何解决此错误?

1 个答案:

答案 0 :(得分:2)

在您的界面中更改

void setSelected();

void setSelected(boolean selected);