If it's just suddenly shutting off, even when it's plugged it, I would assume something inside is loose and causing it to short out.
If it's on battery when it happens, maybe the pins connecting the battery is loose/worn.
Having typed that, if it's something loose inside the laptop causing a short, hitting the table really hard should also cause it to turn off.
If the laptop dusty? Maybe it just needs a cleaning?