So you can certainly legally not hire people over 35 years old, as long as they're not yet 40.
Once they're 40, you can not discriminate against them because they're too old (eg: Fred can't do that job, he's 50 years old) or too young (eg: We can't hire Joe for the CEO job, he's only 42.)
Of course there are many reasons to hire/not hire someone, but if you're using age as a criteria, you are on very shaky ground legally.