The first point I would stress on is that you don't program the autopilot. You program the FMS (Flight Management System), which looks like a very large calculator. In this picture it is the device under then first officer's hand.
On top of the PFD (Primary Flight Display) you see the MCP (Mode Control Panel). This is what controls the modes that the autopilot system will follow, here is another image of it:
Typically the entire flight plan is programmed into the FMC and then during various stages of flight, the autopilot is engaged to help with navigation.
This flight plan includes the departure, enroute waypoints or tracks, and then generally the arrival at the destination; but that is it - it does not include the runway information, etc (as this may be subject to change).
The FMC takes this information and other data (weight, fuel, temperature, weather, etc.) to calculate a flight plan which is then displayed; and the pilot will then select and activate a flight plan.
In most commercial flights however, the flight plan is already loaded in the FMC from the flight operations department and the pilots simply select the predefined flight plan. Punching in a large flight plan takes a significant amount of time so many times this is already downloaded from the flight ops center.
At any stage of flight, the autopilot may be armed and engaged to do one of many things - either maintain thurst, or heading, or control the climb/descent; or follow the flight plan. It may also be disarmed during any stage of flight.
If the autopilot is armed and it set to follow the FMC's flight plan; then after the last waypoint it will follow the waypoint heading.
So, if the last way point is a holding pattern, it will continue on that pattern. If the last waypoint was a marker it will reach that marker, and then continue at that heading and speed; even though there are no more commands coming to it from the FMC (since its at the end of the programmed flight plan).
Note that reaching the end of the flight plan from the FMC does not disengage the autopilot; there are many other things that might do that though.
All the above comes from my time in a 737 and 777 simulator.