What 4wd means for compact tractors - and also most 4wd PU trucks - is that there is an operator control that tells the transmission to send power to drive the front axle as well as the rear axle. When the front axle is also powered it is then possible for any of the 4 wheels to be driven...hence: 4wd
But a because each axle has a differential, driving all 4 tires at the same time also requires some way to lock the differentials. So without "lockers" you only get 2 of the 4 driven at any time....but that's another level of complexity.
You also asked what is the alternative to "mechanical". It is "hydraulic" - drive via a fluid motor in the axle or hub instead of by driveshaft and gears. MFWD vs HFWD.
HDFD and AWD is not nearly so common as 4wd via MFWD in the under-100 hp tractors.
However, MFWD is simple and relatively cheap to manufacture since the invention of the front bevel drive - about 1975. The big downside to 4wd MFWD is that it is a part time traction improvement for getting through difficult places & not for using full time. 4wd is not AWD; it lacks the necessary center differential that all AWD have.
There are a few compact tractor sized AWD full time true 4wd tractors with Hydraulic Front Wheel Drive instead of MFWD. The Bobcat Toolcat is one, the USA made Ventrac is another. Both excellent, not too common, and relatively expensive. Also you will find that type of hydraulic drive on larger European tractors and big construction machines like skip loaders.
Hope this helps,
rScotty