Although I think...
the average velocity means, total distance over total time
so consider the formula speed=distance/time.
And break it down, the first part:
speed=40 km/h, time 2 h
distance= speed *times* time
= 40 * 2
= 80 km
Then the second part:
speed=60 km/h, time 2 h
distance= speed *times* time
= 60 * 2
= 120 km
Total distance / Total time = Average Velocity (keep in mind the basic formula speed=distance/time)
therefore, (120+80) km / 4 hrs
= 50 km/h
Hope I helped :)