Here, total distance covered is = 20 + 20 = 40 km
The first 20 km it travels at 40 km/h, the time taken is = 20/40 = 1/2 h
Next 20 km it travels at 60 km/h, the time taken is = 20/60 = 1/3 h
So, average speed is = total distance/total time
= (40)/(1/2 + 1/3)
= (40 × 6)/(5)
= 48 km/h
Regards