A:AnswerYes. I use this lens on both my Canon Rebel XTi/400D and 70D, both of which have cropped sensors. While I can't speak specifically to the 40D, it is my understanding it also has a cropped sensor. As a result, I would think this lens would also work on the 40D.
A:AnswerSeeing as how this is a Canon EF mount lens, it’s safe to assume you would need to buy an adapter to use it on your Sony A6000. I believe Sony makes a similar 50mm lens for around $200.