Because the Sun produces light, and we can measure this light to figure out how hot the surface of the sun is. This can be done very precisely and so we know that the suns surface is about 5770 +/- 50 Kelvin degrees above absolute zero. You can do the same thing with a heated, red iron rod in a furnace.
All answers are provided by Dr. Sten Odenwald (Raytheon STX)
NASA IMAGE/POETRY Education and Public Outreach program.