It depends on the cog. Some cheap cogs are simply stamped out of sheet metal to form the teeth and a flange, and threads are cut into the flange. I've seen cases where these strip out, ruining the threads on the hub.
Here's an example of a cheap, stamped cog:
While a Dura-Ace cog isn't the fanciest cog out there, it is well-made and machined, not stamped to form the teeth and threads.