在日食中我正在尝试使用boxbug,然而,它一直告诉我,公共无效行为凌驾于info.gridworld.actor.Bug

时间:2013-02-15 03:18:30

标签: java gridworld

这是我尝试使用的代码(在Mac上):

import info.gridworld.actor.Bug;
/**
* A <code>BoxBug</code> traces out a square "box" of a given size. <br />
* The implementation of this class is testable on the AP CS A and AB exams.
*/
public class BoxBug extends Bug
{
private int steps;
private int sideLength;

 /**
 * Constructs a box bug that traces a square of a given side length
 * @param length the side length
 */
public BoxBug(int length)
{
    steps = 0;
    sideLength = length;
}

/**
 * Moves to the next location of the square.
 */

public void act()
{


    if (steps < sideLength && canMove())
    {
        move();
        steps++;
    }
    else
    {
        turn();
        turn();
        steps = 0;
    }
}
}

它一直告诉我,当我点击侧面的错误三角形时,它找不到“附加源”。我不知道该怎么办。

2 个答案:

答案 0 :(得分:0)

可能该方法在Bug超类上被声明为final。

最终方法的Java文档说明如下:

  

你可以声明一些或所有类的方法final。你用的是   方法声明中的final关键字表示该方法   不能被子类覆盖

http://docs.oracle.com/javase/tutorial/java/IandI/final.html

答案 1 :(得分:0)

我将代码复制并粘贴到Eclipse中,它运行正常。检查您的方法是否与Bug类具有相同的返回值。而对于记录,GridWorld代码的 none 是最终的。它意味着要改变。