If two lights are shining in your room, one red and one blue, how do you know which one is red and which is blue?
If you look at the two lights, the lens in your eye will focus the red light at a different place from the blue light, so you can see two lights in different places. Even though the light that reaches your eye is mixed, the lens can separate the light.
Telescopes have lenses (or curved mirrors that do the same thing). The light from different stars is focused by the telescope, to form an image, and so the light from different stars is separated. The light from individual stars can then be split into colours. This is the star's spectrum.
The job of the telescope is two-fold: collect a lot of light and then focus it so that individual objects can be seen and analysed individually.
There are many ways of classifying a spectrum, Stars have continuous spectra crossed by dark lines. The temperature of the star changes the spectrum, the stars are classified in order
O B A F G K M from hottest to coolest. Nebula sometimes have emmission spectra which looks mostly dark, crossed by bright lines.