These things work effectively like a switched mode power supply.
When an output transistor is conducting, such as in an amplifier, it is somewhere between fully on or fully off, this means that it has to handle the remaining power supply voltage that is not being transmitted to the output.
This means it has to drop voltage across it, and it gets hot.
There are differant working bias points, Class A is when the output device is set halway between the supply voltage and zero volts (keep it simple here).
When you alter the base voltage on the transistor, it can swing its output terminal between 0volts right up to supply volts.
It turns out that if the transtor output terminal is at supply volts, then it is not conducting any current, and so it cools down, and if the output device is turned fully on, then the output terminal drops to near 0volts, and the device is called saturated, it means there is little voltage across the output device, and so again it cools down.
Class A bias is very wasteful of power, because even when there is no output it has a significant voltage across it.It has plenty of other problems but some audio-analists claim it produces better sound quality (not true by the way)
Class B bias employs 2 output devices, both are biased to be very nearly fully off. When the input signal rises above 0 volts, it turns one device on and the other off, and when the input signal falls down below 0 volts then the reverse is true, you have to have a means of producing a power supply that gives you + voltage, 0 volts, and -voltage, this is called a split power rail.
Only one device is conducting at one time, the standing still or doing nothing waste is small, there are issues with setting up such a system well. You can get larger power outputs more easily than in Class A bias.
In summary, an output device that is fully on, does not get hot, and one that is fully off does not get hot.
If this can be exploited then much smaller devices can be used, as heat dissipation is normally the limiting factor.
In Class D bias, what you do is set up your devices to be turned very hard off.
You then find a way to switch them very hard on.
One way to do this is to have a high frequency switching signal, maybe around 100k times per second.
This leaves a short interval between switching signals.
What you do is vary the width of the switching on period, and you do the calculations to average the power out (integration).
For instance, if you have a switching gap of one second, and you switch the power on for half that time, then you have half the maximum power output, this is done in much smaller periods of time in real life.
What the final effect is, is that you do not need large output devices, you do not need large heatsinks and you can make the whole thing very much smaller, and since it runs cooler, it is more reliable.
Your power supply unit can use smaller and cheaper components too.
In practice, you have to find a way of smoothing out the one/off periods, which means some sophisticated filtering systems.
You can get large amounts of power out of relatively low voltages, compared to say, class A bias, you can combine such a system with a switch mode power supply and get very large power outputs, which is why in auto electrics car hifi can run at over 1000Watts.
Another adavantage of class D amplifiers is that you can use them instead of having louspeaker crossover networks, they are so small that you can make them act as extremely accurate filters, so that one class D amp will only operate across a very specific frequency range - and you then feed the output to a speaker element designed to that particular range - this can also lead to large cost savings because a class D amp can be smaller and cheaper to make than a large multiway high power crossover network.
The quality of output compared to input depends immensely on the designer, but take a look at something like a 500Watt Class D module, and compare it in size to a Class A module, its hard to belive that the 2 are doing pretty much the same job, such is the huge differance in size.