JohnnyT got it, here's the answer as copied:
One of the things that people find difficult is that you have not specified the distance, but in fact the answer is the same, whatever the distance. The answer is that there is no answer - there is no speed you can drive at that will make your average speed 40 miles per hour. The reason is that to make your average speed for the whole journey 40 miles per hour, you need to be at your destination NOW, and no speed will allow you to achieve this.
How does this come about? Well, suppose you started out at 2 o'clock, and your destination is exactly 40 miles away. For your average speed to be 40 miles per hour, you need to arrive at 3 o'clock. But you drove the first half of the journey, 20 miles in this case, at 20 miles per hour. Which has taken you an hour. So it is now 3 o'clock, and you have only covered half the distance. There is no speed that you can drive for the second half of the journey that will make the average speed 40 miles per hour, since you need to be at your destination at this moment. And this applies no matter what the distance of the journey. If you prefer, you can change everything to kilometres per hour, instead of miles per hour.