Class B is the more common design used for solid state amps, especially smaller
and older amps. The class also applies to tube amps, but only talking about solid
state amps here.

In a class B amp, the output transistors must dissipate some of the total power being
supplied to the output stage. The rest is delivered to the load. At full output, most
of the power is sent to the speaker, but about 25% is lost by the output transistors
as heat. At lower levels, the percentage of power lost in the transistors is higher.
For example at 1/2 power, 50% is lost in the output transistors.
This means that the transistors must be relatively large and mounted on a large heat
sink. This adds size and weight to the amp. Also, these amps often use linear
power supplies - 60 Hz transformer, rectifier, etc. These large transformers also
add a lot of weight.

In a class D amp, the ouput transistors are operated as switches; they are either
full on, or full off, hence the name switch mode. When a transistor is off, there
is no current through it, and the power dissipated by the transistor is zero. When
the transistor is on, the voltage across the transistor is zero, so again the power
dissipated is zero. Think of the switch on a toaster. When it is off there is no
current through the switch or the heating element. No current, no power. When the
switch is on, the switch remains cold even though it is carrying the full current
to the element.
So the class D amp approaches 100% efficiency, delivering all of the power to the
speaker and having very little lost in itself. This means smaller transistors and
heat sinks. These amps often also have switching power supplies (same principle as
the amp) and eliminate the heavy 60 Hz transformer. A much smaller high frequency
transformer is used. So lots of size and weight savings.

The classes (A, B, AB, C) refer to the biasing of the transistor or tube used in an amplifier
stage. Class A is biased in it's linear operating region. Class B is biased at or near it's
off state. In an audio amp, Class B is used if the stage is "push pull" with one transistor
handling the positive portion of the signal and one transistor handling the negative.
Class AB is biased in the linear region, but not in the center of the region like class A,
but closer to the off state (the "cutoff" point). Although the device itself is operated in a
nonlinear manner, the overall response of the amplifier stage can be linear, and will be
for audio amps. Class C is biased beyond cutoff and used in certain RF stages.

Class D is not a biasing scheme in the same sense as the others. It was simply assigned
the next available letter, if I'm not mistaken. It does not stand for "digital".

So how do you get audio out of a couple of switches?
The transistors are switched at a very high rate. If you look at the average voltage level at
the output transistors, you will see a value that depends on the relative on / off times of the
two two transistors. If each are on for equal time periods, the average will be zero. This is
what occurs during a zero signal condition. If the positive transistor is on for a longer period
than the negative one, then the average will be some positive value. And the longer it is on,
relative to the negative side, the more positive the average will be. The same is true if the
negative transistor is on for a longer time compared to the positive. Except now the average
will be some negative value.
The circuit that drives these output transistors uses the audio signal to control the relative on
and off times. The result is an on /off time for the transistors that very closely follows the voltage
level of the signal. This means that the average voltage level at the transistor output also closely
follows the audio signal. Now all you need to do is remove the high switching frequency from the
output, which is done by filtering as it is above the audio range. All that remains then is the average,
which is a perfect analog of the input signal.