On something like this, the cost to produce remains relatively fixed. Its 6MP sensor was already "old tech" when the camera was introduced and a lot of the other hardware components are all "platform" parts that are shared which have relatively steady and low prices as well. Therefore maximum profit is made on the first units sold, at an MSRP of $599. Companies love early adopters and love it when there's lots of them, because that's where they make all of their money. After awhile the hype and sales fade a bit, so they drop the price a little to encourage more buyers. Then they go into kits at Costco. Then they offer the special two lens kits with a camera bag and memory cards and bundle it. Then they drop the basic kit price even more. Then they offer refurb units for $399 with a lens and a warranty! By this point they're really not making too much money on the actual kit. What they're doing is getting their foot in the door for future sales, because they know that eventually all of their new D40 owners are going to want more advanced lenses, like the 70-300VR for $500. An SB-600 flash for $180. A 17-55 f/2.8 pro zoom lens for $1200.

A 12-24 wide angle for a bit less than that, etc. They flood the market with as many D40's as they can, and then intentionally limit the supply of lenses, including the really nice ones, to keep the ASP (average selling price) high on those to keep margins high.