How to call methods from the super class?

48 Views Asked by At

This bug is supposed to be irremovable from the grid by itself. Is there a way to make the ConnorBug do the removeSelfFromGrid() from the original Bug class and actually get rid of the bug from the grid?

public class ConnorBug extends Bug
{
    public static int MyNewCounter = 0;
    public ConnorBug()
    {
        setColor(null);
    }
    public void removeSelfFromGrid()
    {
        Location loc = getLocation();
        Grid<Actor> gr = getGrid();
        Location next = loc.getAdjacentLocation(getDirection());
        if(gr.isValid(next))
        {

            this.move();
        }
        else{
            this.setDirection(getDirection()-180);
            this.move();
        }
        for(int c=0; c<8; c++)
        {

            Location thatLoc = getLocation();
            Location thatNext = thatLoc.getAdjacentLocation((0+(45*c)));
            if(gr.isValid(thatNext)&&!(gr.get(thatNext) instanceof ConnorRock)&&!(gr.get(thatNext) instanceof ConnorBug))
            {

                ConnorRock something = new ConnorRock();
                something.putSelfInGrid(gr,thatNext);
            }
        }
    }

}
1

There are 1 best solutions below

2
roeygol On

You just need to use:

super.<method name>();

Either if the function is static, you can just Bug.<method name>();