Why do different colors absorb different amounts of heat?

Some colours - such as white - reflect sunlight while others - such as black- absorb it. So it isn't clever to drive a black car if you live in a hot climate.