The drink is carbonated as it is put in the bottle and the lid is screwed on. So all the teeth-rotting-ly fizzy goodness is still there when you open it.
just to expand on maincs_ yes the (flat) liquid is put in the bottle. the machine then "fires" carbonated gas into the bottle and puts the lid on, all under pressure.
Carbon Diaoxide(CO2) Id disolved in the liquid to create a mildly dialuted Carbonic Acid, the bubbles are the CO2 escaping from the surface.
If you check the pH of a freshly opend bottle and he pH of a flat bottle you will notice a sagnificant difference.