Over geological time, each planet creates heat in its interior due to several processes, including the decay of radioactive minerals. The interiors of massive planets are also hotter than the surfaces due to the enormous pressure of gravity within the planet. If we have a hot interior and a cooler exterior, our discussion of equilibrium tells us that heat will flow outward. The heat is transferred to the surface by heat transfer processes such as we have discussed. For example, in the Earth, internal heat travels through the rock by conduction and also by convection in molten rock masses, which rise and descend in sluggish convection currents. Energy then leaves the surface as thermal radiation. Thus, a planet (like any warm rock) slowly cools over geological time as it radiates its heat into space.
Diagram of the internal structure of the Earth. Click here for original source URL
Schematic of the parts of the Sun. Click here for original source URL.
A star creates much more energy in its central region than a planet through nuclear reactions. This intense energy release heats the central core of the star to a temperature of millions of degrees. The heat is transferred from the hot central core to the cooler surface (a few thousand degrees) by a combination of radiation and convection. Finally, it is radiated into space as thermal radiation from the star's surface layers. It takes tens or hundreds of thousands of years for radiation to to get from the core of a bright star in the night sky to its surface, but only a decade or a century to reach us.