From
http://www.kenrockwell.com/nikon/105fe.htm
for a quick answer
"AF traditional screw-type. Won't autofocus on a D40, but so what: just tape the focus ring to 6 feet and you'll always be in focus manually."
From
http://www.dpreview.com/reviews/NikonD40/
which explains why the lens is compatible but will be manual.
"Auto Focus only for AF-S or AF-I lenses
Perhaps the biggest negative on the D40 is that it doesn't have an internal focus drive motor and hence no mechanical focus drive pin, instead it only has CPU contacts which means it can only Auto Focus with AF-S and AF-I lenses (those with built-in focus motors). Indeed our 'standard' lens the Nikkor 50 mm F1.8D (and the F1.4D) are manual focus only on the D40. The images below show the difference between the mount on the D40 and D80, the D80 has a mechanical focus drive pin at about the 7 o'clock position. "
So yes it is compatible as with almost every Nikon lens, but will require manual focusing.