If using the Goal class, you should probably have the goal look for Mario and remove him when intersection occurs. The world class code can still check for lack of Mario in the world and set the new level.
public void boundary()
{
if(getX()<=21){
setLocation (21, getY());
}
Levels L = (Levels)getWorld();
if(L.setupLevel(2)){
if(getX()>=348){
setLocation (348, getY());
}
}
}