The second law of thermodynamics states that heat can flow spontaneously from a hot object to a cold object; heat…