The driveshaft isn’t directly connected all the way to the wheels with sets of rigid gears/attachments. If they were, then you couldn’t brake without slowing the engine down. There’s something called a torque converter, which is like a disc filled with fluid with two fan blades pointed at each other. One fan blade connects to the engine side, one fan blade connects to the wheel side. When the engine spins the driveshaft, it turns one of the fan blades, which starts moving the fluid around, which will start to push the other fan blade around, which turns the wheels. If the wheels can’t move, either because you’re on an uphill or because you’re braking, then the second fan blade can’t turn, and the energy from the motor just goes into swirling that fluid around and pushing harder on the second fan blade. So that’s how it’s possible to be in gear and rev an engine but not have the drive shaft snap.
Latest Answers