The ball will bounce back, relative to the train, with a velocity of 40 m/s. Since the train is going at 30 m/s relative to the ground, then the ball is going at 70 m/s relative to the ground.
I described it to myself as: In the train's reference frame, the ball is approaching the stationary train at 40 m/s. Since it is a perfect elastic collision, the ball rebounds off the train, now moving at 40 m/s in the opposite direction.
A coordinate translation back to the initial reference frame of the thrower yields 40 m/s + 30 m/s = 70 m/s.
Maybe I shouldn't have given that hint. Or would you guys have got it anyway?
Also, do you think we should post these kinds of questions every once in a while to this forum? (questions that don't really require much math, but have somewhat unexpected answers)
Consider the train as the frame of reference, initially not moving, and the tennis ball travelling toward it at 40mph. In a perfect elastic collision, we need to conserve both momentum and kinetic energy. That means that if the speed of the ball is s and the speed of the train is S, and the mass of each is m and M respectively, and we denote final speeds by s' an S',
s'm + S'M = -40m
S' = -(40m-s'm)/M
If we assume that the ball's mass is negligible compared to the train, then this is very close to zero, and the train is propelled imperceptibly slowly in the negative direction. In order to preserve kinetic energy, then the ball has the same speed with respect to the train as it did before, 40mph.
Then the answer is that the ball's final velocity relative to the ground is 70mph.
EDIT: Just realized the answer was already provided above.