The RetroBug problem from the 2012 AP Computer Science Exam tests your understanding of inheritance by asking you to extend the Bug class from the GridWorld Case Study.

RetroBug is #2 from the 2012 AP Computer Science A Free Response.

RetroBug class

public class RetroBug extends Bug
    private Location prevLoc;
    private int prevDir;

    public void act()
        prevLoc = getLocation();
        prevDir = getDirection();


    public void restore()
        if(prevLoc != null)

            Actor atPrev = getGrid().get(prevLoc);
            if(atPrev == null || atPrev instanceof Flower)

2012 AP CS Exam Free Response Solutions

Help & comments

Get help from AP CS Tutor Brandon Horn

Comment on RetroBug