Distance = (Rate)(Time) So, Time = Distance / Rate
Let D = one-way distance. Then:
Time it takes to go from A to B = D/40
Time it takes to go from B to A = D/60
Average speed = (Total Distance) / (Total time)
= 2D / [D/40 + D/60]
= 2D/[D/24] = 2D(24/D) = 48 km/hr