Energy is conserved if the amount of heat lost by one fluid is the same as the heat gained by the second fluid. The heat loss may result in a decrease in the temperature of a fluid while temperature of the second fluid may increase after gaining the heat.
The heat lost by fluid 1 = mass of fluid x specific heat of fluid x temperature change
= 100 g x specific heat of water x (80 - 60) J
Similarly, heat gained by fluid 2 = mass of fluid x specific heat of fluid x temperature change
= 100 g x specific heat of water x (40 - 60) J
A comparison of the two equations show that they are basically the same (ignore the sign, since heat loss is considered negative). Since the values for temperature change, grams of water, and specific heat are the same in the equations, the amount of heat lost by fluid 1 is the same amount as the heat gained by fluid 2. Since the heat lost by fluid 1 is same as the heat gained by fluid 2, there is no loss of energy in this system and hence the total energy of the system is conserved.
Hope this helps.