Using the First law of thermodynamics we know that the final temperature of the two will be identical. Let is call that temperature T degree Celsius. Using the formula Q = m* c* Dt (where Dt means Delta T i.e. The change in temperature, m is the mass of substance and c is the specific heat of the substance) we can find out heat absorbed by the cold water which by the principle of conservation of energy equals the heat released by the hotter water. Q(released by hot water) = - m *c* (T - 40) = Q(absorbed by cool water) = m *c* (T -20) => -T + 40 = T - 20 => 2 * T = 60 => T = 30 degrees Celsius