Why do stars have absorption spectra?

Absorption spectra are a result of light of a certain wavelength exciting an atom from a lower energy level to a higher one and at the same time being absorbed. However, the atom should eventually go back down to its lower energy state, and at the same time emit a photon of same frequency it absorbed earlier. Overall, no changes to the star's spectrum should occur.

Stars have plenty of "cold" gas (atoms in their ground states). If you put some gas on the way from a light source to you, some frequencies will be less represented (dark absorption lines) than non resonance frequencies. Atoms for such frequencies are like a fog on the light way - they capture and diffuse the resonance frequencies to the whole solid angle $4\pi$. So you observe them as less represented than the neighboring non resonance frequencies in the continuous spectrum.