The head of the class is the top place, and the foot of it is the bottom. The joke needs both meanings of foot: last in the row, and the end of a leg.