You have to take into account the TIME at each speed.....the TIME to travel the same distance will be LONGER for 40 m/hr vs 60 m/hr so the AVERAGE will be weighted more toward the 40 m/hr ...
40 x t1 = d d/40 = t1
60 x t2 = d d/60 = t2
2d/avg = t1 + t2 = d/40 + d/60
2d/avg = (3d+2d)/120
2/avg = 5/120
avg/2 = 120/5
avg = 240/5 = 48 m/hr