Electronic drum machines use one of two approaches to create sounds. The first of these is synthesis. As with a melodic synthesiser, this involves using electronic means to fabricate a sound from scratch. A drum or percussion synthesiser is just like any other synth plugin - and most synths can be used to create drum sounds in some way - albeit adapted to suit percussive duties. This usually means the inclusion of specific drum engines, designed to synthesise things like kicks, snares and hi-hats, and a rhythmically-focussed sequencer.
A lot of vintage drum machines used synthesis to create sound, the most notable example being the Roland TR-808, which is still renowned for its sub-heavy synth kicks and metallic cymbal tones.
Synth drums are, unsurprisingly, often synthetic sounding, but can be very flexible since a dedicated drum synth will usually offer plenty of controls to shape the timbre of your raw sound.
The second - and these days more common - method is sampling. This involves using a recorded sound as the primary source. When it comes to drum production, this is commonly a ‘one-shot’ sample - ie, a simple, short recording of a drum or percussion hit - that plays once each time it’s triggered. However, some instruments also work with looped recordings or ‘multisamples’, which use multiple variations of a sound for more realistic and varied results.
Sampling is a better approach for recreating realistic drum sounds and ‘real world’ timbres. It is, however, beholden to the breadth and quality of your available sample library.
In reality, most modern drum machines combine elements of both approaches. Some will offer individual simple and sampling generators side-by-side. Even straightforward sample-based instruments tend to incorporate elements of synthesis, by letting users adjust the pitch of a sample, apply filters, modulation and shape the output with envelopes.